I'm very new to codesys (and plc programming), so I'm not only looking for a solution but some explanation would be very welcome
I've installed codesyscontrol service on my Pi, and followed some simple tutorial for making a LED blink with webvisu. (this works fine)
I also have an RFID module attached to the Pi, and (for now) I handle serial communication with a Python script. (later I would like to use the serial data from RFID inside codesys application, but like I said first time with codesys so 1 step at a time)
However, when the codesyscontrol.service is active ( $ systemctl | grep codesys) I cannot read serial data with the Python script anymore. I figured this was because the Pi only has 1 UART, so I got an FTDI USB serial port adapter to handle the serial communication with the RFID module. I edit the Python script to use /tty/USB0 instead of /tty/AMA0, but I have the same problem: when I stop the codesys service everything works fine, as soon as I start codesys service it stops working.
I've gone through the forum and I've tried adding
[SysCom]
Linux.Devicefile=/dev/ttyUSB
to CODESYScontrol.cfg but this doesnt fix my problem.
So some questions...
1: Can someone explain why codesyscontrol.service would cause this problem?
2: What exactly does [SysCom]
Linux.Devicefile=/dev/ttyUSB
do? I suspect it points codesys to the correct hardware address for serial communication?
3: In some forum posts I see
portnum := COM.SysCom.SYS_COMPORT1
added to the .cfg, what does this do?
4: Final question, how do I fix my problem?
Thank you in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is the python code that stops working when codesys service is active. Any ideas how to get both of them working in parallel?
\#!/usr/bin/envpython3importRPi.GPIOasGPIOimportserialENABLE_PIN =18       #TheBCMpinnumbercorrespondingtoGPIO1SERIAL_PORT='/dev/ttyUSB0' #Thelocationofourserialport. Thismay
               #varydependingonOSandRPiversion. The\#SERIAL_PORT='/dev/ttyS0'  #RPi3hasapparentlyused'ttyAMA0'for
               #Bluetoothandassigned'ttyS0'totheGPIO
               #serialport,souncommenttheappropriate
               #SERIAL_PORTdefinitionforyoursetup.
               #Failingthat,checktheoutputof:
               #  $dmesg|grepserial
               #togetanideaastowhereserialhasbeen
               #assignedto.
              Â
defvalidate_rfid(code):
  #Avalidcodewillbe12characterslongwiththefirstcharbeing
  #alinefeedandthelastcharbeingacarriagereturn.
  s=code.decode("ascii")
  if(len(s)==12)and(s[0]=="\n")and(s[11]=="\r"):
    #Wematchedavalidcode. Stripoffthe"\n"and"\r"andjust
    #returntheRFIDcode.
    returns[1:-1]
  else:
    #Wedidn't match a valid code, so return False.    return False  def main():  # Initialize the Raspberry Pi by quashing any warnings and telling it  # we'regoingtousetheBCMpinnumberingscheme.
  GPIO.setwarnings(False)
  GPIO.setmode(GPIO.BCM)
  #ThispincorrespondstoGPIO1,whichwe'll use to turn the RFID  # reader on and off with.  GPIO.setup(ENABLE_PIN, GPIO.OUT)  # Setting the pin to LOW will turn the reader on. You should notice  # the green LED light on the reader turn red if successfully enabled.  print("Enabling RFID reader and reading from serial port: " + SERIAL_PORT)  GPIO.output(ENABLE_PIN, GPIO.LOW)  # Set up the serial port as per the Parallax reader'sdatasheet.
  ser=serial.Serial(baudrate=2400,
            bytesize=serial.EIGHTBITS,
            parity  =serial.PARITY_NONE,
            port   =SERIAL_PORT,
            stopbits=serial.STOPBITS_ONE,
            timeout =1)
  #Wrapeverythinginatryblocktocatchanyexceptions.
  try:
    #Loopforever,oruntilCTRL-Cispressed.
    while1:
      #Readin12bytesfromtheserialport.
      data=ser.read(12)
      #Attempttovalidatethedatawejustread.
      code=validate_rfid(data)
      #Ifvalidate_rfid()returnedacode,displayit.
      ifcode:
        print("Read RFID code: "+code);
  except:
    #Ifwecaughtanexception,thendisablethereaderbysetting
    #thepintoHIGH,thenexit.
    print("Disabling RFID reader...")
    GPIO.output(ENABLE_PIN,GPIO.HIGH)
   Â
if__name__=="__main__":
  main()
 Â
Hi all,
I'm very new to codesys (and plc programming), so I'm not only looking for a solution but some explanation would be very welcome
I've installed codesyscontrol service on my Pi, and followed some simple tutorial for making a LED blink with webvisu. (this works fine)
I also have an RFID module attached to the Pi, and (for now) I handle serial communication with a Python script. (later I would like to use the serial data from RFID inside codesys application, but like I said first time with codesys so 1 step at a time)
However, when the codesyscontrol.service is active ( $ systemctl | grep codesys) I cannot read serial data with the Python script anymore. I figured this was because the Pi only has 1 UART, so I got an FTDI USB serial port adapter to handle the serial communication with the RFID module. I edit the Python script to use /tty/USB0 instead of /tty/AMA0, but I have the same problem: when I stop the codesys service everything works fine, as soon as I start codesys service it stops working.
I've gone through the forum and I've tried adding
[SysCom]
Linux.Devicefile=/dev/ttyUSB
to CODESYScontrol.cfg but this doesnt fix my problem.
So some questions...
1: Can someone explain why codesyscontrol.service would cause this problem?
2: What exactly does
[SysCom]
Linux.Devicefile=/dev/ttyUSB
do? I suspect it points codesys to the correct hardware address for serial communication?
3: In some forum posts I see
portnum := COM.SysCom.SYS_COMPORT1
added to the .cfg, what does this do?
4: Final question, how do I fix my problem?
Thank you in advance.
This is the python code that stops working when codesys service is active. Any ideas how to get both of them working in parallel?
Related
Talk.ru: 11