I'm facing some issue with the internal connection (UART) of the Raspberry 3 and Codesys 3.5.15.SP4.
If I read everything right internal interface GPIO 14/15 should work with RS 485.
Activate serial via raspi-config.
Unable bluethooth:
$ echo 'dtoverlay=pi3-disable-bt' | sudo tee -a /boot/config.txt
$ sudo systemctl disable hciuart
Removed /etc/systemd/system/multi-user.target.wants/hciuart.service
$ sudo reboot
add in sudo nano /etc/CODESYSControl.cfg
Linux.Devicefile=/dev/ttyAMA or ttyS
portnum := COM.SysCom.SYS_COMPORT1
With AMA -->Modbus Master is green, but Slave doesn't connect...
With ttyS--> Modbus Master is red...
Communication via USB-RS485-Adapter works...
Any hints or tipps what could be modified?
Regards
Benedikt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I deleted the SysCom entry in /etc/CODESYSControl.cfg and added in /etc/CODESYSControl_Users.cfg: [SysCom]
Linux.Devicefile.1=/dev/ttyAMA
-->Modbus Master stays red
If I add Linux.Devicefile=/dev/ttyAMA (without .1)
-->Modbus Master gets green but still Slaves stays red/yellow
Under USB everything works fine...Any thoughts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've been reading through this thread and have tried most solutions to try and achieve RS232 comms via USB adapter. The difference is the hardware I am using is an HMI from ifm Electronic (Codesys SP15 Patch1), running Linux version 4.14.98-yocto-standard.
I've tried many variations of the CODESYScontrol.cfg and CODESYScontrol_User.cfg files for SysCom settings but none delivered a good result. The Linux commands to read and write using the USB adapter seem to work fine, it just seems that the link for Codesys is not successful. The latest firmware of the device actually already includes the SysCom configuration in the CODESYSControl.cfg, but there are multiple copies in different file locations - perhaps a problem?
Using 'dmesg' I can see that the USB ports are assigned as ttyUSB0, ttyUSB1 and ttyUSB2, and that the FDTI serial device has been recognised and mounted properly.
I was originally using the SysCom library, but have used the SerialComWithVisu example to make sure it wasn't my code that was incorrect. Neither the example or my code using SysCom.lib can make a connection. I seem to get a valid handle from SysComOpen but SysComSetSettings and SysComRead are returning an error (RTS_IEC_RESULT = 1). Although I assume the SysComRead is returning an error because of invalid COM settings. I have attached my COM settings - please tell me if they are wrong.
The code that I wrote with the SysCom library works no problem on an embedded PLC from ifm, so I'm confident in the settings and the code - I just think there is something I need to do on the Linux side for the HMI.
This seems to work now, but the data I am receiving is not right - this could be my USB adapter or hardware set-up, but if you (or anyone else in the community!) have any pointers then that would be very helpful!
I am usuing Hercules to send:
'Hello'
But I am receiving this in my Codesys application:
'ÿ'
I am also not receiving any data from the Codesys Application, despite the SysComWrite function returning 0 (no error). Perhaps I have a wiring problem?
Best regards,
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to do a project with Raspberry Pi 4 and Codesys that includes a USB / Modbus adapter, which works perfectly, and a SIM7600E device connected to the GPIO because I need to send information by SMS from the program.
With this last device I am having problems. I've prepared a python script that works fine from the Raspberry (even with the Codesys app running), but it doesn't from the Codesys.
Another test script, which turns on an LED in the GPIO when it should send an SMS, works without problems from Codesys, so I imagine the problem must be that Codesys cannot communicate with the UART due to lack of some configuration.
I have reviewed countless forum posts and am unable to find a solution.
This is a screenshot of the CODESYSConfig.cfg. I made this configuration for the USB / Modbus adapter.
Is another silyl configuration required for the UART?
Any suggestions where the problem could come from?
Thank you .
Hi Edwin,
Thank you very much for the help and I hope you have enough patience to assist me ;-).
I have modified the /etc/CODESYSControl_User.cfg file as directed.
I understand that I must include in my CODESYS project, in the device tree, a USB device that is associated with / dev / ttyS0 through the COM2 address, but the devices that I can add are of type Modbus_COM_Port
Are these equivalent to a COM device?
Should I add a Modbus_Serial_Device or Modbus_Master_Device with a Modbus_Eslave_Device afterwards?
Regards.
Víctor
Hello again, Edwin.
I feel like I need a little more help, because I still can't send an SMS from the application created with Codesys. I hope you can give me some other clue.
I finally bought the IIoT library from the Codesys store and installed it on Codesys V3.5 SP16.
I use the SendSMS function to try to send an SMS, but without success (error 5013?).
I don't know if I need to use any of the other COM port activation functions, or the modem, etc. (Unfortunately I cannot find a user guide or detailed help for this library, its functions and an example).
As an illustration, I attach the Python script that works correctly and sends the SMS from the Raspberry Pi console.
Thank you very much.
Regards,
Victor.
Hi,
if your modem support the follwoing at commands:
Used AT-Commands
AT+CMGS: Send Message
AT+CMGR: Read Message
AT+CMGL: List Messages
AT+CMGD: Delete Message
AT+CMGF: Message Format
AT+CPMS: Preferred Message Storage
AT+CSCA: Service Center Address
AT+CMEE: Error Message Format
AT+CREG: Network registration
it might work.
You need to add the comport here:
/etc/CODESYSControl_Users.cfg
[SysCom]
Linux.Devicefile.1=/dev/ttyS0
That's it... example project comes with the SMS package.
Regards
Edwin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Edwin.
Yes, the modem supports AT commands, but where do I write them? In a POU? How do I indicate the COM port of the UART?
When I use the example included in the SMS Service SL library, modified for the raspberry, the TimeOut runs out on the first initialization of the modem and it goes into error. I suspect it has to do with the ModemFb.itfConnectionType
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm having some trouble with the serial communication. I am using raspberry pi on rasbian with V3.5.16.0.
The com port appears to start properly, and I even notice some activity on the usb serial port (it is connected to an arduino), but all reads and writes appear to be empty (despite reporting successful).
cat /dev/ttyACM0 lists no activity.
If i start the arduino serial port monitor first, before initializing the com port in codesys, everything works perfectly. All activity shows up in cat /dev/ttyACM0 and the arduino code responds (i have it flipping the LED when receiving a message).
udiPort = 1
Baud rate is 115200
parity= None
one stop bit
udi timout 0
udibytesyze=8
udibinary=0
Been a while but I wanted all to know I found the source of this issue and the solution. The problem was initiating the serial communication caused the arduino to reset. If serial communication started from the raspberry pi before the arduino reset the messages would be lost and would not recover. Putting a small delay before starting read/write reliably solved the problem.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Been a while but I wanted all to know I found the source of this issue and
the solution. The problem was initiating the serial communication caused
the arduino to reset. If serial communication started from the raspberry pi
before the arduino reset the messages would be lost and would not recover.
Putting a small delay before starting read/write reliably solved the
problem.
Been a while but I wanted all to know I found the source of this issue and
the solution. The problem was initiating the serial communication caused
the arduino to reset. If serial communication started from the raspberry pi
before the arduino reset the messages would be lost and would not recover.
Putting a small delay before starting read/write reliably solved the
problem.
Sure! You might notice whenever you start the serial monitor in the arduino IDE the sketch reboots. Well I discovered the same thing happens when the serial port is opened on the raspberry pi in codesys. For some reason, if read or write commands are sent before the sketch restarts it's serial port again everything is lost.
The solution is to open the port, then wait a bit (my program waits for 1 second). After 1 second, you can read/write and everything will work.
Here is a portion of code I used, adapted from some other examples i found on the web for serial communication via codesys and raspberry pi.
A couple of libraries used here
CAA SerialCom 3.5.15.0
CAA Types 3.5.13.0
I hope you get everything working! Let me know how it works out. This was a hard topic to find, most serial communication conversation revolves around using the GPIO pins. Using the USB port is very convenient since it powers the arduino and has the already active built in serial communication available.
Hello there, I have the strong feeling that I am going insane. I am trying to implement RS232 reading via an USB adapter on a RevPi (Raspberry). It worked perfectly fine until now. I was able to read the port but now it is not doing anything but giving all kinds of error codes (which are documented here: https://help.codesys.com/webapp/Errors;product=CmpErrors2_Itfs;version=3.5.15.0) but hardly ever the same one.
I enabled the ttyUSB2 (which is used in my case) in the CODESYScontrol.cfg. I tried enabling it in the CODESYScontrol_User.cfg, I tried "LinuxDevicefile.1=/dev/ttyUSB2" and the line "portnum := COM.SysCom.SYS_COMPORT1" - absolutely nothing works.
Here is my minimal implementation which used to work perfectly:
Even the SerialCom example from Codesys does not work. I am using the SysCom lib, because the CAA lib did not work at all for me. Any help is appreciated, thank you very much!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I already ruled out the hardware and the cable part. I am able to read the data using cat /dev/ttyUSB0 - the driver seems to be working. It is no issue with my laptop aswell.
The Codesys file seems correct aswell, I even rewrote it and compiled a completely new file... Maybe it is not the way to do it via Codesys directly - maybe it is easier to read the input with another device and send it to Codesys via some protocol (OPC UA, MQTT idk..). I need it to be as tight as possible on the long run.
Cheers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello together,
I'm facing some issue with the internal connection (UART) of the Raspberry 3 and Codesys 3.5.15.SP4.
If I read everything right internal interface GPIO 14/15 should work with RS 485.
Unable bluethooth:
$ echo 'dtoverlay=pi3-disable-bt' | sudo tee -a /boot/config.txt
$ sudo systemctl disable hciuart
Removed /etc/systemd/system/multi-user.target.wants/hciuart.service
$ sudo reboot
add in sudo nano /etc/CODESYSControl.cfg
Linux.Devicefile=/dev/ttyAMA or ttyS
portnum := COM.SysCom.SYS_COMPORT1
With AMA -->Modbus Master is green, but Slave doesn't connect...
With ttyS--> Modbus Master is red...
Communication via USB-RS485-Adapter works...
Any hints or tipps what could be modified?
Regards
Benedikt
No one on this topic?
Hi,
remove if there is an section in /etc/CODESYSControl.cfg and add change it here in:
/etc/CODESYSControl_Users.cfg
[SysCom]
Linux.Devicefile.1=/dev/ttyAMA
if USB com port should be your Com1 in CODESYS...
BR
Edwin
Hi Edwin, thanks a lot!!!
I deleted the SysCom entry in /etc/CODESYSControl.cfg and added in /etc/CODESYSControl_Users.cfg:
[SysCom]
Linux.Devicefile.1=/dev/ttyAMA
-->Modbus Master stays red
If I add Linux.Devicefile=/dev/ttyAMA (without .1)
-->Modbus Master gets green but still Slaves stays red/yellow
Under USB everything works fine...Any thoughts?
Hi there,
I've been reading through this thread and have tried most solutions to try and achieve RS232 comms via USB adapter. The difference is the hardware I am using is an HMI from ifm Electronic (Codesys SP15 Patch1), running Linux version 4.14.98-yocto-standard.
I've tried many variations of the CODESYScontrol.cfg and CODESYScontrol_User.cfg files for SysCom settings but none delivered a good result. The Linux commands to read and write using the USB adapter seem to work fine, it just seems that the link for Codesys is not successful. The latest firmware of the device actually already includes the SysCom configuration in the CODESYSControl.cfg, but there are multiple copies in different file locations - perhaps a problem?
Using 'dmesg' I can see that the USB ports are assigned as ttyUSB0, ttyUSB1 and ttyUSB2, and that the FDTI serial device has been recognised and mounted properly.
I was originally using the SysCom library, but have used the SerialComWithVisu example to make sure it wasn't my code that was incorrect. Neither the example or my code using SysCom.lib can make a connection. I seem to get a valid handle from SysComOpen but SysComSetSettings and SysComRead are returning an error (RTS_IEC_RESULT = 1). Although I assume the SysComRead is returning an error because of invalid COM settings. I have attached my COM settings - please tell me if they are wrong.
The code that I wrote with the SysCom library works no problem on an embedded PLC from ifm, so I'm confident in the settings and the code - I just think there is something I need to do on the Linux side for the HMI.
Summary of set-up:
If you need further details I'll happily share them.
Best regards,
John
Hi John,
which runtime version does this CR1059 have?
(goto plcshell -> rtsinfo
BR
Edwin
Hi Edwin,
Thank you for your quick response!
My RTS version is 3.5.15.10.
Best regards,
John
Hi Edwin,
My CODESYSControl.cfg file was:
But now I have removed the ';'
This seems to work now, but the data I am receiving is not right - this could be my USB adapter or hardware set-up, but if you (or anyone else in the community!) have any pointers then that would be very helpful!
I am usuing Hercules to send:
'Hello'
But I am receiving this in my Codesys application:
'ÿ'
I am also not receiving any data from the Codesys Application, despite the SysComWrite function returning 0 (no error). Perhaps I have a wiring problem?
Best regards,
John
Baudrate?
Hello,
I am trying to do a project with Raspberry Pi 4 and Codesys that includes a USB / Modbus adapter, which works perfectly, and a SIM7600E device connected to the GPIO because I need to send information by SMS from the program.
With this last device I am having problems. I've prepared a python script that works fine from the Raspberry (even with the Codesys app running), but it doesn't from the Codesys.
Another test script, which turns on an LED in the GPIO when it should send an SMS, works without problems from Codesys, so I imagine the problem must be that Codesys cannot communicate with the UART due to lack of some configuration.
I have reviewed countless forum posts and am unable to find a solution.
This is a screenshot of the CODESYSConfig.cfg. I made this configuration for the USB / Modbus adapter.
Is another silyl configuration required for the UART?
Any suggestions where the problem could come from?
Thank you .
hi,
since 3.5SP15 you could do it that way:
/etc/CODESYSControl_Users.cfg
[SysCom]
Linux.Devicefile.1=/dev/ttyUSB0
Linux.Devicefile.2=/dev/ttyS0
I assume that you access the GPIO by:
/dev/ttyS0
In CODESYS later your USB serial is Com1 and GPIO Uart Com2
BR
Edwin
Hi Edwin,
Thank you very much for the help and I hope you have enough patience to assist me ;-).
I have modified the /etc/CODESYSControl_User.cfg file as directed.
I understand that I must include in my CODESYS project, in the device tree, a USB device that is associated with / dev / ttyS0 through the COM2 address, but the devices that I can add are of type Modbus_COM_Port
Are these equivalent to a COM device?
Should I add a Modbus_Serial_Device or Modbus_Master_Device with a Modbus_Eslave_Device afterwards?
Regards.
Víctor
Hi,
yes... but here in the config.
BR
Edwin
Hello again, Edwin.
I feel like I need a little more help, because I still can't send an SMS from the application created with Codesys. I hope you can give me some other clue.
I finally bought the IIoT library from the Codesys store and installed it on Codesys V3.5 SP16.
I use the SendSMS function to try to send an SMS, but without success (error 5013?).
I don't know if I need to use any of the other COM port activation functions, or the modem, etc. (Unfortunately I cannot find a user guide or detailed help for this library, its functions and an example).
As an illustration, I attach the Python script that works correctly and sends the SMS from the Raspberry Pi console.
Thank you very much.
Regards,
Victor.
Hi,
if your modem support the follwoing at commands:
Used AT-Commands
AT+CMGS: Send Message
AT+CMGR: Read Message
AT+CMGL: List Messages
AT+CMGD: Delete Message
AT+CMGF: Message Format
AT+CPMS: Preferred Message Storage
AT+CSCA: Service Center Address
AT+CMEE: Error Message Format
AT+CREG: Network registration
it might work.
You need to add the comport here:
/etc/CODESYSControl_Users.cfg
[SysCom]
Linux.Devicefile.1=/dev/ttyS0
That's it... example project comes with the SMS package.
Regards
Edwin
Hi Edwin.
Yes, the modem supports AT commands, but where do I write them? In a POU? How do I indicate the COM port of the UART?
When I use the example included in the SMS Service SL library, modified for the raspberry, the TimeOut runs out on the first initialization of the modem and it goes into error. I suspect it has to do with the ModemFb.itfConnectionType
Check the modem documentaion... To Figuren Out which device on the Pi /dev/tty.... Ist used
I'm having some trouble with the serial communication. I am using raspberry pi on rasbian with V3.5.16.0.
The com port appears to start properly, and I even notice some activity on the usb serial port (it is connected to an arduino), but all reads and writes appear to be empty (despite reporting successful).
cat /dev/ttyACM0 lists no activity.
If i start the arduino serial port monitor first, before initializing the com port in codesys, everything works perfectly. All activity shows up in cat /dev/ttyACM0 and the arduino code responds (i have it flipping the LED when receiving a message).
udiPort = 1
Baud rate is 115200
parity= None
one stop bit
udi timout 0
udibytesyze=8
udibinary=0
stty -F /dev/ttyACM0:
speed 115200 baud; line =0;
min=1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
CODESYSControl.cfg has:
Linux.Devicefile=/dev/ttyACM
Any other ideas?
Been a while but I wanted all to know I found the source of this issue and the solution. The problem was initiating the serial communication caused the arduino to reset. If serial communication started from the raspberry pi before the arduino reset the messages would be lost and would not recover. Putting a small delay before starting read/write reliably solved the problem.
I use Raspberry pi3 B+ and CODESYS for TTL connection
PLC use: PiXtend
Can you provide more information
tehthoams forge@codesys.com 於 2021年2月2日 週二 上午12:37寫道:
I come from Taiwan
qaz478566 forge@codesys.com 於 2021年2月2日 週二 上午11:26寫道:
Sure! You might notice whenever you start the serial monitor in the arduino IDE the sketch reboots. Well I discovered the same thing happens when the serial port is opened on the raspberry pi in codesys. For some reason, if read or write commands are sent before the sketch restarts it's serial port again everything is lost.
The solution is to open the port, then wait a bit (my program waits for 1 second). After 1 second, you can read/write and everything will work.
Here is a portion of code I used, adapted from some other examples i found on the web for serial communication via codesys and raspberry pi.
A couple of libraries used here
CAA SerialCom 3.5.15.0
CAA Types 3.5.13.0
I hope you get everything working! Let me know how it works out. This was a hard topic to find, most serial communication conversation revolves around using the GPIO pins. Using the USB port is very convenient since it powers the arduino and has the already active built in serial communication available.
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 7
Hello there, I have the strong feeling that I am going insane. I am trying to implement RS232 reading via an USB adapter on a RevPi (Raspberry). It worked perfectly fine until now. I was able to read the port but now it is not doing anything but giving all kinds of error codes (which are documented here: https://help.codesys.com/webapp/Errors;product=CmpErrors2_Itfs;version=3.5.15.0) but hardly ever the same one.
I enabled the ttyUSB2 (which is used in my case) in the CODESYScontrol.cfg. I tried enabling it in the CODESYScontrol_User.cfg, I tried "LinuxDevicefile.1=/dev/ttyUSB2" and the line "portnum := COM.SysCom.SYS_COMPORT1" - absolutely nothing works.
Here is my minimal implementation which used to work perfectly:
Even the SerialCom example from Codesys does not work. I am using the SysCom lib, because the CAA lib did not work at all for me. Any help is appreciated, thank you very much!
Hi! Sounds like your problem is a few layers below your application. So if
it worked already, and now doesn't. I assume it is either a problem of:
To exclude the first two, you could test the adapter on another PC or
device.
To see if the linux driver works at all, you may test it when CODESYS is
not running, with minicom or s.th. similar.
In the CODESYS configuration I can only imagine, that:
this in the log)
Good luck!
Cheers,
Ingo
Hey Ingo, I am sorry for the late reply!
I already ruled out the hardware and the cable part. I am able to read the data using cat /dev/ttyUSB0 - the driver seems to be working. It is no issue with my laptop aswell.
The Codesys file seems correct aswell, I even rewrote it and compiled a completely new file... Maybe it is not the way to do it via Codesys directly - maybe it is easier to read the input with another device and send it to Codesys via some protocol (OPC UA, MQTT idk..). I need it to be as tight as possible on the long run.
Cheers