Error "An invalid device OR an invalid constant is being used" when compile simple GX Works 2 program in FX3G PLC - plc

I have FXCPU PLC FX3G series and I create ST Structured Project in GX Works 2. The problem is I cannot loop through an array of bits. Here are my local variables.
Now this code in a program compiles with error
(* Do not compile! *)
FOR iCount := 0 TO 2 DO
arOfBits[iCount] := TRUE;
END_FOR;
But this code works fine
(* Compile *)
arOfBits[1] := TRUE;
The compile error as follows
No.: 1
Result: Error
Data Name: POU_01
Class: Program compile
Content: An invalid device OR an invalid constant is being used
Error Code: F0137
If that would be array of Words that would work fine in both examples. If it would be array of STRUCT where one property there is bit and another is WORD, then both examples would work with WORD but only the last example with bit.
The nature of the problem is that if I use Device like D100 or variable as is in example I cannot access bits but only words. To access bits, I have to use constant as array index.
Does anyone know how to address this issue?

Related

How to understand the beat in chisel language?

I am studying the design of riscv-Boom. It is designed with chisel. When I read its source code, I always cannot understand when the signals in these circuits will be obtained. Normal programs are executed one by one. But hardware languages like chisel are not.
https://github.com/riscv-boom/riscv-boom/blob/master/src/main/scala/exu/issue-units/issue-slot.scala
For example, the link above is the source code of Issue-slot in Boom.
103: val next_uop = Mux(io.in_uop.valid, io.in_uop.bits, slot_uop)
113: state := io.in_uop.bits.iw_state
126: next_state := state
127: next_uopc := slot_uop.uopc
128: next_lrs1_rtype := slot_uop.lrs1_rtype
129: next_lrs2_rtype := slot_uop.lrs2_rtype
155 slot_uop := io.in_uop.bits
208: for loop
This is some code in the IssueSlot class in the link above. For the chisel hardware language, these := should mean that they are connected together by wires. So do these signals change at the same time? For example, when io.in_uop.valid is true, does the above code assign values at the same time?
For example, the current uop is fmul, and in_uop= is fadd. When io.in_uop.valid, the above code will be executed at the same time. But there is a problem.
origin
uop = fmux
when io.in_uop.valid
103: val next_uop = io.in_uop.bits (fadd uop)
113: state := io.in_uop.bits.iw_state (fadd state)
126: next_state := state (fmux state)
127: next_uopc := slot_uop.uopc (fmux uopc)
128: next_lrs1_rtype := slot_uop.lrs1_rtype (fmux lrs1_rtype )
129: next_lrs2_rtype := slot_uop.lrs2_rtype (fmux lrs2_rtype )
155 slot_uop := io.in_uop.bits (faddlrs2_rtype )
208: for loop
When io.in_uop.valid is true, the transmit slot at this time will be input fadd information. At the same time, the original fmul information will still be output to next-related signals. This should be unreasonable. Where does the problem occur?
For the for loop of line 207. I still find it difficult to understand. Will the for loop be executed in one beat? For example, if I use a for loop to traverse a queue, when did the for loop finish?
If anyone is willing to answer me, I would be extremely grateful!
first
The a := b expression mean that b is connected to a yes. b is the source and a the sink.
If a new connection to a is done after in the code, it will be replaced.
In the following code, a is connected to c:
a := b
a := c
This writing could be strange but it's usefull to set a default value in conditionnal branch.
For example :
a := b
when(z === true.B){
a := c
}
By default, a will be connected to b except when z is true.
second
Do not forget that Chisel is an HDL generator. It generate hardware code, some keywords are pure Scala like if, for, ... and other are hardware chisel keyword like when, Mux, ...
Then the for loop in line 208 is executed at the code generation stage. And it will generate some hardware chisel when mux code.
I'd highly recommend you spend some time with the Chisel Bootcamp. It can really help you grasp the generator aspects of chisel.

Displaying Data as a String in Simulink RT Display Port

My issue involves using the RS-232 Simulink RT blocks.
A model is uploaded to the target PC (xPC) and it transmits and receives data from a variable frequency drive (VFD) that controls a motor. The issue arises on the receiving end when I take data and try to send that data to a display block in my model as a string. Code would be helpful here:
disp = uint8(zeros(1,24));
display = uint8(zeros(1,length(disp)));
cmd = 0;
status = stat_lb;
%% Start-Up
% Initialization Period
if (status == 0 || status == 1)
cmd = 0;
msg = uint8('Start up');
display = [msg uint8(zeros( 1, length(disp)- length(msg) ))];
end
...
%Multiple status cases with unique displays.
...
disp = display
So, here the cmd portion functions as expected. As noted above, I want to display the display string on a display block in my Simulink model. As you can see, though, it is of type uint8, so I need to convert it to type string; however, when I pass it through either the ascii2str Simulink block or just place it in the function call (e.g. display = ascii2str(display)) I get the following error message:
Executing the 'CheckData' command produced the following error: Invalid parameter/value pair arguments
My thought is that this has something to do with the fact that I am using MEX and this function (ascii2str) is not supported. Anyways, I am wondering if anyone knows why I receive this error and if there is anything I can do to resolve it.
Oh, and one last thing: I can get the display to work if I just remove the ascii2str; however, the only problem with this is that the display is in uint8 form and not really helpful. So, if there is any other way that I can decode the uint8 to a string I am all ears.
Thanks!
I have found that there is no support for this feature in Simulink RT. One option is to use external functions, but I found it better for my application to simply output a number and have a table in the simulation that explained what each number meant.

Simple UDP socket in VC++ MFC

I have been trying to write a working program that takes in data from a UDP socket and displays it in an edit control box as you receive the data (My exposure to c++ is also only about a week :P have only done embedded C code before). I have a working program that can send and output data on a button click but I want something that can do it in real time. The aim is scale this up into a larger GUI program that can send control data to hardware and get responses from them.
I have run into various problems including:
The program just not executing my OnReceivefunction (derived from
CAsyncSocket)
Getting the OnReceive function to run on a separate thread so that it can still run after a button has been clicked sending a control packet to the client then waiting for a response in a while loop
Not being able to output the data in the edit box (tried using both CEdit and CString)
ReplaceSel error saying that the type char is incompatible with LPCTSTR
My code is based on this codeproject.com tutorial, being almost exactly what I want but I get the error in 4.
EDIT: the error in 4. disappears when I change it to a TCHAR but then it outputs random chinese characters. The codeproject.com tutorial outputs the correct characters regardless of char or TCHAR declaration. When debugged my code has type wchar_t instead type char like the other code.
Chinese output
In the working program echoBuffer[0] the character sent and displayed was a 1
UINT ReceiveData(LPVOID pParam)
{
CTesterDlg *dlg = (CTesterDlg*)pParam;
AfxSocketInit(NULL);
CSocket echoServer;
// Create socket for sending/receiving datagrams
if (echoServer.Create(12345, SOCK_DGRAM, NULL) == 0)
{
AfxMessageBox(_T("Create() failed"));
}
for (;;)
{ // Run forever
// Client address
SOCKADDR_IN echoClntAddr;
// Set the size of the in-out parameter
int clntAddrLen = sizeof(echoClntAddr);
// Buffer for echo string
char echoBuffer[ECHOMAX];
// Block until receive message from a client
int recvMsgSize = echoServer.ReceiveFrom(echoBuffer, ECHOMAX, (SOCKADDR*)&echoClntAddr, &clntAddrLen, 0);
if (recvMsgSize < 0)
{
AfxMessageBox(_T("RecvFrom() failed"));
}
echoBuffer[recvMsgSize] = '\0';
dlg->m_edit.ReplaceSel(echoBuffer);
dlg->m_edit.ReplaceSel(_T("\r\n"));
}
}
After reading the link that #IInspectable provided about working with strings and checking the settings differences between the two programs it became clear that the issue lay with an incorrect conversion to UNICODE. My program does not require it so I disabled it.
This has cleared up the issue in 4. and provided solutions for 2 and 3.
I also think I know why another instance of my program would not run OnReceivein 1. because that file was not being defined by one that was already being run by the program, but that is now irrelevant.

Error while compiling to LINUX Matlab Code with MatlabR2012a

I am trying to compile a Matlab function to C.
Here you have the declaration of the function:
function [SpdLmt0, SpdLmt1, SpdLmt2, SpdLmt3, SpdLmt4, SpdLmt5, SpdLmt6,
SpdLmt7, SpdLmt8, SpdLmt9, SLDst0, SLDst1, SLDst2, SLDst3, SLDst4,
SLDst5, SLDst6, SLDst7, SLDst8, SLDst9, IntTyp1, IntTyp2,
IntTyp3, IntTyp4, IntTyp5, IntTyp6, IntTyp7, IntTyp8, IntTyp9,
IntTyp10, IntDst1, IntDst2, IntDst3, IntDst4, IntDst5, IntDst6,
IntDst7, IntDst8, IntDst9, IntDst10, StpDst1, StpDst2, StpDst3,
StpDst4, StpDst5, StpDst6, StpDst7, StpDst8, StpDst9, StpDst10,
BumpDst1,BumpDst2,BumpDst3,BumpDst4,BumpDst5,BumpDst6,BumpDst7,
BumpDst8,BumpDst9,BumpDst10,SlopeVal1,SlopeVal2,SlopeVal3,SlopeVal4,
SlopeVal5,SlopeVal6,SlopeVal7,SlopeVal8,SlopeVal9,SlopeVal10,
SlopeDst1,SlopeDst2,SlopeDst3,SlopeDst4,SlopeDst5,SlopeDst6,
SlopeDst7,SlopeDst8,SlopeDst9,SlopeDst10,Radius1,Radius2,Radius3,
Radius4,Radius5,Radius6,Radius7,Radius8,Radius9,Radius10,CurvDst1,
CurvDst2,CurvDst3,CurvDst4,CurvDst5,CurvDst6,CurvDst7,CurvDst8,
CurvDst9,CurvDst10,UDP_error] = parser(UDP, longitud)
So I receive UDP data from a "UDP Receive" Simulink block for LINUX. The received message is composed by 100 data (the outputs of the function) codified in ASCII Code. My function "parser" takes the UDP message and decodifies it to have the desired outputs.
The problem is when I try to compile it with the Simulink Coder I have this message:
Error: Errors occurred - aborting
Someone can help?
Without more information about the function, it's hard to know exactly what might be happening, but one recommendation is that you adjust the function call itself a bit. With that many return values, it's entirely possible that MATLAB Coder encountered an error in converting the function. It's pretty unusual to have that many return values, and it may cause problems.
I would suggest putting your return values into a single data structure (a struct or an array depending on what is appropriate). This would simplify your function call and perhaps help Coder out.

Perl uninitialized value in numeric gt?

I'm a beginner in Perl and I get this message when I execute my code:
Use of uninitialized value $triggerCheck in numeric gt (>) at
./advanced-daemon.pl line 101.
This is the only error/warning I get when executing my code. The code, itself, works without any problems but I'm wondering what's the problem in that variable?
To reproduce the problem you can use this code:
while(1==1)
{
my $triggerCheck = "10";
if($triggerCheck < 10)
{
print "This var is < 10";
}
$triggerCheck = 9;
sleep 1;
}
Edit: I solved my problem. Sorry for bothering you all :)
There is absolutely nothing wrong with that code that you initially posted. Nor the code that you replaced it with (other than the annoying infinite loop).
It gets no errors or warnings and, when I change the initialisation to "9", it outputs the string.
In fact, given that your error message is complaining about > and there's no such symbol anywhere in your code, you have a serious mismatch between reality and your presentation of it.
Seriously, put together the minimal complete code sample that generates the error and post that. Helping people over the net is hard enough without being hobbled by fiction :-)