Shop OBEX P1 Docs P2 Docs Learn Events
BS2 serial communications with PLC?? — Parallax Forums

BS2 serial communications with PLC??

Turnbull2112Turnbull2112 Posts: 65
edited 2013-01-17 22:54 in BASIC Stamp
I have a set of sensors on a board that is being controlled with a BS2. I would like to connect the BS2 to a PLC control network for remote monitoring of the sensors the BS2 are running. Is this possible to go through the programming port with RS-232 to monitor these data points? Would I need extensive software on my end or can I tell the PLC operator what addresses to monitor? Pointing me in the right direction would be appreciated.

Thanks,

Rob

Comments

  • SapphireSapphire Posts: 496
    edited 2013-01-14 19:43
    Rob,

    The programming port on the BS2 can be used to communicate with another device such as a PLC with RS-232. However, you will not be able to use the PLC to examine memory in the BS2. The most common method is for the BS2 to send the sensor data out the programming port to another device, which captures it and does further processing. In any case, if your existing software in the BS2 is not setup to do this, then modifications to the BS2 program would be required to send the data out. The PLC could then be programmed to recieve it and do the remote monitoring.
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2013-01-15 04:15
    Excellent thanks, I will try to research this further. Any recommendations?

    Thanks,
  • stamptrolstamptrol Posts: 1,731
    edited 2013-01-15 06:06
    You can indeed get the Stamp and the PLC to communicate.

    The ideal situation is for the Stamp to send data to the PLC via a serial link. The PLC will likely have a communication buffer and that will make the process easier. The Stamp can poll its sensors, do any local signal processing, then send the data out to the PLC.

    If you must get the PLC to talk to the Stamp, use a low baud rate (4800 or lower) as the Stamp doesn't have a com buffer and can easily miss incoming data.

    I've been working with an alternative microcontroller that does MODBUS natively and in the background. It is probably the easiest way to move significant data back and forth. PM me if you're interested.

    Cheers,
  • MarcelMarcel Posts: 32
    edited 2013-01-17 22:54
    Hi TurnBull2112,

    What you are asking isn't so difficult. But it takes some reading. Go the modbus.org and download MODBUS over Serial Line Specification and Implementation Guide V1.02. http://modbus.org/tech.php.
    The only problem you encounter is that the Modbus RTU needs needs the CRC16 check. There is a lot of information and control calculation to check if you are on the right track. Modbus uses big endian so the This means 'that when a numerical quantity larger than a single byte is transmitted, the most significant byte is sent first. Here is the CRC16 function that I use in a language Xbasic and works correct. Checked at http://www.lammertbies.nl/comm/info/crc-calculation.html.

    There is an CAS Modbus RTU parser from Chipkin and that little program helps you to see if the Modbus message you want to send is OK. http://www.chipkin.com/technical-resources/cas-modbus-rtu-parser/

    The CRC start value is 0xFFFF and you much calculate the CRC over the bytes to send except the CRC itself.

    FUNCTION CRC16 AS N (CRC as N, A as N)
    dim i as n
    crc = crc .XOR. a
    for i = 1 to 8
    if (crc .AND. 1) then
    crc = int(crc / 2)
    crc = crc .XOR. 40961
    else
    crc = int(crc / 2)
    end if
    next
    CRC16 = crc
    END FUNCTION

    I use the function as follows:
    'CRC16(crc,field)
    crc = hex_to_dec("FFFF")'Modbus seed value
    crc = CRC16(crc,mbadu.reqpdu.SlaveAddress)
    crc = CRC16(crc,mbadu.reqpdu.FunctionCode)
    crc = CRC16(crc,mbadu.reqpdu.StartingAddressHighOrder)
    crc = CRC16(crc,mbadu.reqpdu.StartingAddressLowOrder)
    crc = CRC16(crc,mbadu.reqpdu.NumberOfPointsHighOrder)
    crc = CRC16(crc,mbadu.reqpdu.NumberOfPointsLowOrder)

    Use the crc value (2 bytes) in the meassage. Don't forget to swap the crc bytes in the message. Big Endian you know :-)

    Have fun!

    Marcel
Sign In or Register to comment.