# You can go from ASCII to Binary

**URL:** <https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308>\
**Category:** Ignition\
**Created:** [September 20, 2011, 3:44pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308 "2011-09-20T15:44:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![F\_Rayon](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@F\_Rayon](https://forum.inductiveautomation.com/u/F_Rayon)\
**Post date:** [September 20, 2011, 3:44pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/1 "2011-09-20T15:44:37Z")

</div>

Hello

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

Thanks

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 20, 2011, 3:47pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/2 "2011-09-20T15:47:52Z")

</div>

What sort of ASCII string is coming in?

---

<div class="post-metadata">

**Author:** ![F\_Rayon](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@F\_Rayon](https://forum.inductiveautomation.com/u/F_Rayon)\
**Post date:** [September 20, 2011, 3:57pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/3 "2011-09-20T15:57:37Z")

</div>

is type char

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 20, 2011, 4:24pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/4 "2011-09-20T16:24:38Z")

</div>

I was thinking in terms of an example of the string. 😉

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

---

<div class="post-metadata">

**Author:** ![F\_Rayon](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@F\_Rayon](https://forum.inductiveautomation.com/u/F_Rayon)\
**Post date:** [September 20, 2011, 4:34pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/5 "2011-09-20T16:34:45Z")

</div>

ok  
example:

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

and be activated one at a time, not all

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 20, 2011, 4:55pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/6 "2011-09-20T16:55:13Z")

</div>

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

```auto
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'`

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 20, 2011, 4:56pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/7 "2011-09-20T16:56:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![F\_Rayon](https://avatars.discourse-cdn.com/v4/letter/f/e68b1a/32.png) [@F\_Rayon](https://forum.inductiveautomation.com/u/F_Rayon)\
**Post date:** [September 20, 2011, 5:01pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/8 "2011-09-20T17:01:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 20, 2011, 10:39pm UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/9 "2011-09-20T22:39:30Z")

</div>

Since I like scripting… 🙂

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.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 21, 2011, 1:20am UTC](https://forum.inductiveautomation.com/t/you-can-go-from-ascii-to-binary/3308/10 "2011-09-21T01:20:15Z")

</div>

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