2.12 Communications with a Windows PC (Visual Basic Application)
Using Automatic Reception with the MP3000 as a Slave
2-336
'---- Clear buffers to zero ----
For i = 0 To 4095
sbuf(i) = 0
Next
'---- Create the 218 header part ----
'---- Set the register type. ----
sbuf(0) = &H11 ’Extended MEMOBUS command
'---- Set the serial number and increment for every transmission ----
sbuf(1) = (iSerial + 1) Mod 256
'---- Set the destination channel number ----
sbuf(2) = &H0 ’Always 0 hex because the PLC channel is undefined
'---- Set the source channel number ----
sbuf(3) = &H0 ’Always 0 hex because channel numbers do not apply to PCs
sbuf(4) = &H0 ’Reserved
sbuf(5) = &H0 ’Reserved
'---- Set the total number of data items from the start of the 218 header to the end of MEMOBUS
data ----
'---- When SFC contains 09, 22 bytes = 218 header (12 bytes) + MEMOBUS data (10 bytes) ----
sbuf(6) = DATAi ’Data length (L)
sbuf(7) = DATAi \ 256 ’Data length (L)
sbuf(8) = &H0 ’Reserved
sbuf(9) = &H0 ’Reserved
sbuf(10) = &H0 ’Reserved
sbuf(11) = &H0 ’Reserved
'---- Create the MEMOBUS data part ----
'---- Length from MFC to end of data ----
sbuf(12) = CByte(MDATAi And &HFF) ’Data length (L)
sbuf(13) = CByte((MDATAi And &HFF00)\256) ’Data length (H)
'---- MFC is always 20 hex ----
sbuf(14) = &H20
'---- SFC ----
sbuf(15) = SFC
'---- Set the CPU number ----
sbuf(16) = CPUNum ∗ 16
sbuf(17) = &H0 ’Spare is always 0 hex