You can go from ASCII to Binary

Hello

I have an interface that takes ASCII code and want to activate some alarms apart from this code can do this.

Thanks

What sort of ASCII string is coming in?

is type char

I was thinking in terms of an example of the string. :wink:

Also, will there be simultaneous alarms or just one at a time?

ok
example:

Trouble 001 OPEN ON PHOTO
YSH-001 INT. CONTROL ROOM

and be activated one at a time, not all

If there are a manageable number of alarms, a SWITCH statement might do the trick

Switch ("Trouble 001 OPEN ON PHOTO YSH-001 INT. CONTROL ROOM",
        "Trouble 002 OPEN ON PHOTO YSH-002 SOME OTHER PLACE",
        "Trouble 003 OPEN ON PHOTO YSH-003 NOWHERE",
        1,
        2,
        3,
        0)

If there are a lot of alarms, I would consider querying the alarm in a table and returning a value

SELECT AlarmVal FROM table WHERE AlarmText ='Trouble 001 OPEN ON PHOTO YSH-001 INT. CONTROL ROOM'

Does the string always begin with “Trouble nnn”? If so, is nnn a unique identifier?

no, if there are variables such as Alarm … 005
caution in … 013

Since I like scripting… :slight_smile:

If the number in the message string is always the first number in the message, then you could iterate through the string and get the alarm code, and then look it up in a table. That way, it wouldn’t matter what the leading text was, the user could change the alarm text at any time, and alarms could be added to the database and control system without making changes to the code.

It isn’t clear to me exactly what you want to do, but here is a code sample where I define a list of three different strings with the ID in different places, and print out the message ID.

a=['This is test 001','Test 002','The last test is 004'] for i in a: for j in i.split(): if j.isdigit(): print 'This is message %d'%j

If the message number isn’t always the first digit (‘System 2: This is Alarm 002’), then regular expressions would have to be used to set up some rules.

Very nice, Step 7! I was looking for something in that direction.