Shop OBEX P1 Docs P2 Docs Learn Events
Directnet plc to bs2 — Parallax Forums

Directnet plc to bs2

WriglyWrigly Posts: 9
edited 2005-11-30 19:41 in BASIC Stamp
Trying to get a v memory location from a plc to a BS2. The PLC is a Koyo DL06 using their Directnet protocal.The first part is a request for data from the BS2 to the PLC, which works right and I get a proper responce. My problem lies with the nest section where I send a SOH header to the PLC giving the information for the location, size and such to the PLC. At this point the PLC can respond in one of two ways, first with a ACK and data requested or with a NAK(not acknowledge) if there are problems. This is where my problem is I always get a NAK. I have tried different settings and request to no avail. I have a question of addressing, as the BS2 is themaster and PLC is the slave, do I have to identify the BS2 in some way as the master? Any help on this would be great.

Thanks Wrigly



' {$STAMP BS2}
' {$PBASIC 2.5}



c1 VAR Word
c2 VAR Word
c3 VAR Word
c4 VAR Word
c5 VAR Word
plc VAR Byte(8)

main:
c1=0
c2=0
c3=0
c4=0
c5=0
plc(0)=0
plc(1)=0
plc(2)=0
SEROUT 1,16468,[noparse][[/noparse]$4E,$21,$05]
SERIN 0,16468,[noparse][[/noparse]c1,c2,c3]
DEBUG CLS,HEX ? c1,HEX ? c2,HEX ? c3
SEROUT 1,16468,
[noparse][[/noparse]$01, ' 1 = SOH
$30, ' 2 = target address byte
$31, ' 3 = target byte address 2
$30, ' 4 = read or write
$31, ' 5 = data type
$30, ' 6 = starting address MSB
$34, ' 7 = starting address MSB
$30, ' 8 = starting address LSB
$31, ' 9 = starting address LSB
$30, ' 10= number of complete blocks
$30, ' 11= number of complete blocks
$30, ' 12= bytes in last block
$34, ' 13= bytes in last block
$30, ' 14= master ID
$30, ' 15= master ID
$17, ' 16= ETB
$30, ' 17= LRC1
$31] ' 18= LRC2
SERIN 0,16468,[noparse][[/noparse]STR plc\2]
DEBUG HEX ? plc(0),HEX ? plc(1),HEX ? plc(2)
END

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-28 15:04
    Wrigley,

    I don't have my DL-06 manual in front of me, but I have a nagging feeling that the DL-06 can support DeviceNet in either sending or receiving but not both. I'll check and re-post.
    Having said that, I could be wrong; in which case it may only be that the DL-06 is starting to talk back before the stamp is ready for the serin command. The DL-06 has a setting to make the plc wait for some period of time before returning the results of the query.
    If this topic is of interest to a number of folks, maybe we could have it moved over to the Sandbox and work on this industrial plc - to- stamp communications.

    Cheers
  • jesawyersjesawyers Posts: 6
    edited 2005-11-28 17:41
    Forget the DirectNet protocol. Go with MODBUS espically considering your using serial communications between the DL06 and the stamp. It's much easier to implement and it would not suprise me if there are example stamp applications already out on the web. If not, just go to www.modbus.org for help on constructing the commands. Since you see to have a good grasp on DirectNet you will find MODBUS easier.

    John
  • WriglyWrigly Posts: 9
    edited 2005-11-28 18:15
    stamptrol,

    Sorry for the miss info, the example code shown has a LRC for ascii. I have tried it with just the hex LRC with the same results. You mentioned timing of the DLO6, as it might be sending the info before the BS2 is ready for it. Can you go into detail further on this as all I could find on the DL06 was for port 2.

    jesawyers,

    Wish I could but I am using a HMI off port 2 on the DL06, which leaves port 1 only left and the two choices are then type K and directnet. I do intend to look into modbus for another app on the boards.


    *edit*
    OOPS stand corrected I can use modbus on port 1 of the DL06 but cannot change any timing, will have to give modbus a shot.

    Post Edited (Wrigly) : 11/28/2005 6:42:27 PM GMT
  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-29 13:03
    Wrigly,

    The delay before sending is described on page 4-48 of the DL06 user manual. Its set in the Comm port setup area and will let you put some time delay in before the plc sends data back to the stamp.

    If you go the Modbus route, I'd be interested in your success. I tried it on an earlier project and found the checksum calculation to be a pain. But, there may be a way to hard code the check sum if you could get to the point of always issuing the same command. When the data comes back to the stamp, you could just ignore the checksum and use the data.

    Cheers
  • WriglyWrigly Posts: 9
    edited 2005-11-30 00:26
    Thanks for all of the help!! I have went to the modbus protocol, ignoring the last CRC byte it is working rather well. Only problem I have now is I want to to use a RS232 serial port with odd parity. I have seen people mention on the forums the max232, would this be posible soluction to the odd parity problem ? I also stumbled across a post where someone mentioned coding the odd parity bit, key word was stumbled across for now I can't find it again HAHA.

    Wrigly
  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-30 01:10
    Wrigly,

    The max232 chip won't take care of the parity problem, it just shifts the voltage levels of the signals.

    Can you post your working modbus code? I assume the stamp is the Modbus master?

    Cheers
  • WriglyWrigly Posts: 9
    edited 2005-11-30 15:06
    I kept the code simple and small. I used a program that would let me verfy my code for each serout to the plc before I placed it in the code (www.modbus.pl) this would let me send requests and receive strings back vis modbus format and actual see what was being tranfered. This was a big help as it pretty much verfired my data for each serout request and gave me the CRC. In return I received the data string with a fixed amout of blocks. I ignore the returned CRC and use the data as I need. The modbus program was a great help in troubleshooting the request out. This setup is a barebone modus tranfer it is not a full blown setup but still rather useful as I poll with the serout every 500ms and use the the return as external watchdog to verfy the plc operation. This is the code line for data transfer.

    SEROUT 15,16468,[noparse][[/noparse]01,03,04,32,00,10,197,55] ' v2040 forward data request
    SERIN 7,16468,500,datacheck,[noparse][[/noparse]STR plc\16]

    I cleared the plc string before each serin from the plc and then verfy first 3 bytes for address and data structure to insure refreshed data set when it times out to datacheck. I am reading a bigger section of data than I need durring each poll but leaves me more room for expansion in either the plc or stamp code as I need without rewriting the modbus request each time I change the data I am monitoring.

    Anyone have any ideal either hardware or code wise on dealing with the odd parity issue?

    thanks again

    Wrigly
  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-30 15:40
    Wrigly,

    Thanks for the info. Makes future work easier to tackle!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-30 19:41
    Wrigly,

    ·· As per our phone conversation I think at this point the better solution for a controller would be the SX28.· With SX/B you could use a familiar PBASIC Style language and accomplish this task using interrupts.· In fact, a couple of our engineers have indicated that it would be posible to develop a ring buffer and send/receive data at two different baud rates/parity/etc.

    ·· What I would recommend is to check out the PDF at the following link.· It is Al·Williams book "Exploring The SX" from our website.· Page 221 may have what you need to see this through.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.