STOD/DTOS confusion. Studio 5000.

JZerb

Member
Join Date
Oct 2016
Location
Here
Posts
423
So what I thought would be simple has turned out not to be, or at least it hasn't become obvious enough to me yet.

I have a DINT coming into a CL5380 from an RFID reader. That DINT is in an array with a length of 10. DataRead[10]. There is also a DINT to write the data to the RFID tag if needed for initial setup, DataWrite[10]. So I wanted to set something up so that the end user can enter a STRING tag on the HMI for the data that they wanted written to the RFID tag, seemed like the STOD instruction would be simple and what I needed to use and it seems as if I may have underestimated what it is I need to do.

I was hoping that I would merely be placing the string data into the STRING tag that was the Source in the STOD and then for the Dest use DataWrite[0] and all would be good. I was incorrect and now that I have sat here and played around with it for a bit all of the methods that I have come up with have confused me even further. To the point where I cannot even get a single letter for example "A" to be written to the tag and then read into the PLC. I will do the write and then the read shows a "0" in the DINT array element that I assumed would read "A", after a DTOS of course. Any advice as to what I need to do to accomplish what it is Im looking to do?
 
STOD will stop converting when it encounters a non-digit in the string (other than a leading '-'). If you need to be writing an 'A' character to the RFID, it sounds like incoming and outgoing data should be string data, but this is contradicted by reading results into a DINT array. So it is not clear how this reader/interface is supposed to work, specifically is the initial setup being sent supposed to be done with an DINT value or a character string?

Edit: I think STOD also skips leading characters until it hits the first numeric or '-', and then converts until reaching another non-numeric or the end of the string.
 
Last edited:
STOD will stop converting when it encounters a non-digit in the string (other than a leading '-'). If you need to be writing an 'A' character to the RFID, it sounds like incoming and outgoing data should be string data, but this is contradicted by reading results into a DINT array. So it is not clear how this reader/interface is supposed to work, specifically is the initial setup being sent supposed to be done with an DINT value or a character string?

Edit: I think STOD also skips leading characters until it hits the first numeric or '-', and then converts until reaching another non-numeric or the end of the string.

So the reader/interface brings the data into the PLC in DINT form. P&F has an AOI which makes this almost too simple to setup honestly. The only snag I’m having is like I said above, I would love to go from a STRING to a DINT so that when I need to write data to a tag its simple to implement on the HMI side.

I can always just stick with using DINTs and have the tags assigned a number then make a table in the PLC that fills out so tag 12467 = ThisThing and 12358=ThatThing. Again my preference would be so the end user could just type in ThisThing and ThatThing from the HMI level in order to create that data to be written to a new tag.
 
Silly question. Is your RFID reader capable of handling alphanumeric data?


If so, the array of DINTS seems a little strange for something with an AOI. AB strings are stored as an array of SINTs (With a LEN), where each SINT is a character. Are your DINTS actually 4 SINTs packed together in one element? If that's the case, you need to be packing all your SINTs into the DINT array, so DataRead[0] or DataWrite[0] is actually the first 4 SINTs of your string and so on.


Can you post any links for the RFID system, app notes or the AOI?
 
Silly question. Is your RFID reader capable of handling alphanumeric data?


If so, the array of DINTS seems a little strange for something with an AOI. AB strings are stored as an array of SINTs (With a LEN), where each SINT is a character. Are your DINTS actually 4 SINTs packed together in one element? If that's the case, you need to be packing all your SINTs into the DINT array, so DataRead[0] or DataWrite[0] is actually the first 4 SINTs of your string and so on.


Can you post any links for the RFID system, app notes or the AOI?


All great questions that I am just not sure of the answers. A call to P&F tech tomorrow am may help my cause a bit but in the meantime here is a link to the AOIs for the specific device.

https://www.pepperl-fuchs.com/usa/en/classid_2474.htm?view=productdetails&prodid=41851#software
 
If my madman ramblings turn out to be correct, you can create a STRING[40] for UI use, strip the LEN by copying it to a SINT[40] and then just dump the SINT array into the DINT array with a COP. I'll see if I have some time tonight to have a look at what's in the link you posted (If someone else doesn't have the answer already).
 
Last edited:
I hope this will help, I just created a couple functions that will allow the HMI to show the characters of a DINT read by an RFID reader, and allow them to type text in and convert it to a DINT. In my display, I have all the affected controls configured for VBA Control and look for the Change event to call the functions. In the ThisDisplay module:

Private Sub strMatrlBadge0_Change()

Me.txtMatrlBadge0.Caption = DINTToCHAR(Me.strMatrlBadge0.Value)

End Sub

Where both the strMatrlBadge0 and txtMatrlBadge0 are configured for VBA Control. Then in a separate module:

Public Function DINTToCHAR(ByVal lngBadge As Long) As String

Dim intPos As Integer
Dim strCHAR As String
Dim lngMult(1 To 4) As Long

For intPos = 1 To 4
lngMult(5 - intPos) = 2 ^ ((intPos - 1) * 8)
Next intPos

For intPos = 1 To 4
lngVal = Int(lngBadge / lngMult(intPos))
lngBadge = lngBadge - lngVal * lngMult(intPos)
strCHAR = strCHAR & Chr(lngVal)
Next intPos

DINTToCHAR = strCHAR

End Function

Public Function CHARToDINT(ByVal strBadge As String) As Long

Dim intPos As Integer
Dim lngVal As Long

If Len(strBadge) < 5 Then
For intPos = Len(strBadge) To 1 Step -1
lngVal = lngVal + Asc(Mid(strBadge, intPos, 1)) * 2 ^ ((Len(strBadge) - intPos) * 8)
Next intPos
End If

CHARToDINT = lngVal

End Function

I'm still working on a dialog box to allow the user to enter a string and have it converted back to a DINT, but that shouldn't be much different.
 

Similar Topics

Hi, folks, how’s going? On our one production line, we use AB Logix5000 as main plc and others as slaves. We name slave plc program as...
Replies
2
Views
1,627
So, in the example below, why is the first two numbers after the $ symbol considered control characters? I would think they should be converted...
Replies
3
Views
2,455
What occurs if a string which has no numbers in it is given as the source? Does the destination change at all? I don't have a system here to test...
Replies
6
Views
2,977
I'm writing a new program for a CompactLogix 5069-L310ER. I used a GSV to grab the date and time from the processor. Then several DTOS and...
Replies
5
Views
2,015
OK, So I have a problem where I have SINT[450] array (Data[x]). I created an index that runs through and does 450 itterations of DTOS instruction...
Replies
4
Views
2,840
Back
Top Bottom