I am trying to communicat on the seriel port on my PLC with this code:
(*Init comport*)TripCounter:=TripCounter+1;IFNOTport_openedTHENÂ Â com_handle:=SysComOpen(com_num);Â Â IFcom_handle<>16#FFFFFFFFTHENÂ Â Â Â port_init:=TRUE;Â Â ELSEÂ Â Â Â SysComClose(com_num);Â Â Â Â com_handle:=SysComOpen(com_num);Â Â Â Â port_init:=TRUE;Â Â END_IF;(*ComPort settings*)Â Â com_set.Port:=com_num;Â Â com_set.dwBaudRate:=9600;Â Â com_set.byParity:=0;Â Â com_set.dwTimeout:=0;Â Â com_set.byStopBits:=1;Â Â com_set.dwBufferSize:=0;Â Â com_set.dwScan:=0;Â Â res:=SysComSetSettings(com_num,ADR(com_set));(*Setup com port*)Â Â IFNOTresTHENÂ Â port_opened:=TRUE;Â Â END_IFEND_IF
I get my com_handle, but things fail when I try to set the settings on the com port, what do I do wrong here?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
shooter hat geschrieben:
is it an extra card or do you want the programming interface to talk (not possible)
It is the port present on my PLC, and yes it is the programming interface too.
So there is no chance to use that programming interface to something else at run time (run time for my PLC code that is)?
BTW I am about to make my PLC send SMS via a GSM modem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
shooter hat geschrieben:
sorry to bad in russian, to read it.
Me too.
But anyway they claim that you can use the RS232 port, and with some question to there support, some reading on there forum I manage to use the port, but first I had to use the right cable, then add the port in the "PLC configuration", and then use the right COM port number.
But that just gives me some new challenge:
1.: How to reset/empty an array?, with a string I can just use MyString := '', but I can't make it work for an array.
2.: How to join two strings? In VB6 I would use something like "NewString = FirstString + NextString"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
```It works well when I single step the code, but the PLC is much faster that my GSM modem so when running the code it never get the answer from the modem.
I had try to make a 5 seconds delay with a While-do loop, but it make my PLC reboot. Is there en more nice way to make a waiting function?
In the help there is an example of "traffic light" with a wait thing, but it is in IL language and I am not ready for this yet.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
WHILE sz < 6 DO
sz:=SysComRead(com_num,ADR(rcvBUF),1024,0);
END_WHILE
But it just make my PLC reboot, just like any other loop I try to kill some time with.
If I put in a breakpoint and start the running of the PLC after 5 seconds of halt at the breakpoint, all is fine and I get my data in the rcvBUF as expected.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to communicat on the seriel port on my PLC with this code:
I get my com_handle, but things fail when I try to set the settings on the com port, what do I do wrong here?
is it an extra card or do you want the programming interface to talk (not possible)
BTW I am about to make my PLC send SMS via a GSM modem.
what PLC is used?
as codesys is running on > 100 types.
sorry to bad in russian, to read it.
But that just gives me some new challenge:
1.: How to reset/empty an array?, with a string I can just use MyString := '', but I can't make it work for an array.
2.: How to join two strings? In VB6 I would use something like "NewString = FirstString + NextString"
join is concat
and no need to empty an array, however you can overwrite it with spaces
another way is use oscat library.
.
Thanks for the fast answer.
I have these two line of code that send a command to a GSM modem, and then get the answer:```
SysComWrite(com_num,ADR(snd_str),LEN(snd_str),0);
sz:=SysComRead(com_num,ADR(rcvBUF),1024,0);
```It works well when I single step the code, but the PLC is much faster that my GSM modem so when running the code it never get the answer from the modem.
I had try to make a 5 seconds delay with a While-do loop, but it make my PLC reboot. Is there en more nice way to make a waiting function?
In the help there is an example of "traffic light" with a wait thing, but it is in IL language and I am not ready for this yet.
test until you see some characters in the buffer, if received enough then go to a sub program to evaluate the received answer.
I try this code:
WHILE sz < 6 DO
sz:=SysComRead(com_num,ADR(rcvBUF),1024,0);
END_WHILE
But it just make my PLC reboot, just like any other loop I try to kill some time with.
If I put in a breakpoint and start the running of the PLC after 5 seconds of halt at the breakpoint, all is fine and I get my data in the rcvBUF as expected.