We would like to provide some hints how scale communication can be tested and how regexp can be configured to get the weight from the response.
1.1. Testing the scale communication
Check the communication port of your device in the Windows Device manager:
Download Docklight application and open the project setting. Set the COM Port Settings.
Double click on the new empty name field on the Send Sequence panel, set the name and the get data command of your scale. Set the get weight command of your device. You can use the HEX codes to see if you entered it correctly.
Press on the ---> button to send the command to the scale. You will receive the response.
You can check it in ASCII and in HEX as well:
Value TX is the command that we sent to the device, and the RX is the value that we received.
1.2. Defining the regexp from the beginning of the received text.
The received text starts with a <LF> character. The hex value of this character is 0a
So this character will be at the beginning of my regexp:
\x0a
Then I have some space characters. I can define it by the hex code of the space character, and an asterix: \x20*
So I will add this to my regexp:
\x0a\x20*
The next group is the weight value. I will put these two characters into parameter 'weight'.
Since I don’t know the length of the value, I will use some characters by expression: .+
The way I define a parameter is the following:
(?’weight’.+)
So I will add this to my regexp:
\x0a\x20*(?'weight'.+)
Since I don’t know the length of the value, I must define the rest characters from the end backwards.
1.3. Defining the regexp from the end backwards
What we want to achieve with the regex is to cut of the value and put it into the weight variable.
The last character of the returned value is: <ETX>
The hex value of this character is 03, so this character will be at the end of the returned value:
\x03
The previous character is: <CR>
The hex value of this character is 0d, so I will add it to the regexp, before the previous character:
\x0d\x03
Then there are some characters, that we do not carte about, this is how I configure it in regexp: .+
I will add it to the regexp, before the previous character:
.+\x0d\x03
Then we have 2 characters after the uom: <CR><LF>
The hex codes are 0d and 0a
I will add it to the regexp, before the previous character:
\x0d\x0a.+\x0d\x03
The next characters are the uom characters. I will put these two characters into parameter uom, but WMS doesn’t use this uom value. The two character represented in regexp by double dot: ..
The way I define a pramater is the following:
(?'uom' InputMask )
So in our case we will put 2 characters into the value, so this will be (?'uom'..)
I will add it to the regexp, before the previous character:
(?'uom'..)\x0d\x0a.+\x0d\x03
Now we defined everything from the end of the received text backwards.
Now we can put the two parts together, and use this regexp in the scale fonfiguration in WMS
\x0a\x20*(?'weight'.+) (?'uom'..)\x0d\x0a.+\x0d\x03
Comments
0 comments
Please sign in to leave a comment.