Does OptoScript have the same code syntax as C?

Hi all,

I am fairly familiar with the C programming language and i am trying to write an optoscript that converts decimal to binary, that being said, I know how to do this in C and I was wondering if optoscript and C are the same language so I wouldn’t need to watch out for anything.

Thanks,
innotech01

Move32bits? This will move the entire bit pattern into an int for you to manipulate. I think this is what you’re after? No conversion needed! Once in an int you can bit bash and then move back with the same command.
I hope this helps

Hi nick stephens,

I am not sure I quiet follow what you’re saying with the Move32bits command. I am looking at the help command on Move32Bits and it says the typical use for this is “To help parse or create binary data when communicating with other devices”.

I was thinking in the line of if I send the value ‘23’, it will return out 10111.

Hello innotech01,

I think the answer kind of depends on what you’re going to do with it next. If you just want to look at the value in PAC Control’s debugger, all you have to do is inspect the variable then change this selection:


and ta-da! PAC Control shows it to you in Decimal, Hex, or Binary. (Kind of like how your Windows Calculator will let you do this if you’ve selected View > Programmer.)

Did you want to display that value in PAC Display or groov? Perhaps turn it into a string?

I speak C, perhaps could could tell me the C equivalent you had in mind?

-OptoMary

Hi mstjohn,

What I am planning to do next was to translate the value to PAC Display. I am trying to read registers via the hyper terminal and lets say for example if I read register 16, it returns the value of 199. Now 199 translated to binary is just 11000111. I see in opto that there is a command, BitTest, which sees whether the specific Bit is on(1) or off(0).
The parameters for BitTest is Item and the Bit to test, in OptoScript it is
BitTest( Item, Bit to Test).

So I can go through each bit and see whether each bit is on or off and depending on the the state of the Bit, I will relay a message to the display saying whether the corresponding bit should display a certain value or not.

For example:

Let’s say I am reading register16, the value it returns is 199.

Now 199 is 11000111 is binary.
Using Bit to test, we can see that the bit numbers 0,1,2,6 and 7 are on and 3,4 &5 are off. The corresponding message related to the bits 0,1,2,6,7 are Pressure, Temperature, Volumetric Flow, Gas Select, Mass Flow respectively are ON so in the display the user reads that they are on.


Now going back to the original question : I have written out how to translate decimal to binary in C, and was wondering if there is a command that does it in Opto. I read the Typical Use and Function for Move32 Bits and I don’t think that’s gonna solve my issue.

This is a long message so thank you for reading all this.

innotech01

hi innotech01
when you say translate decimal (im assuming a float value here) to binary (something that you can bit bash or read its bit status in pac display) then to get the float value into a valid format you need to move it into an integer variable. to do this the move32bits moves the whole 32bit value of the float variable to an integer. once in an integer you can manipulate as you see fit.
to display in PAC Display you then assign say a text element to the control engine driven attribute to something (visibility, rotate, text in from control engine, etc…), select your integer variable and bit index. if you want it to display On or Off corresponding to the bit value, then select Discrete in the dynamic attribute window (im using a text in from control engine example here) and add the text you want if the bit is on or off.
I think this is what you want to do??




Hi nick stephens,

I think we are mixing up the fact that you might be assuming that I already have my decimal translated to binary and then taking the integer part of the float and playing with it. The thing is I am still stuck on the first part, in the translation. I think you might be going about this the bitwise operator method if i am not mistaken ?

-innotech01

Hi,
I just talked with the PSG at OPTO and they said, as mstjohn , that the I can view the number I sent in as a decimal, binary or hex.
What I am now wondering is if I can save the variable as a binary form and then use that variable later for different uses as I mentioned above.

thanks,
-innotech01

Hi innotech01,

I’m confused about what you’re starting with and where you’re trying to go with it. You mentioned HyperTerminal which makes me think you might be starting with a string?

If this is the case, then you might either have a[I] string representation[/I] of a integer, or some binary data packed into the string.

If you have a string representation of a decimal number, you’ll need to use a command like “Convert String to Integer 32” (or similar). If you have a string representation of a hex number, you could use “Convert Hex String to Number.”

If it’s “binary” data stored in a string, that’s a little more complicated and you have to worry about things like byte order (endianness).

Once you have an Int 32 (or 64), you can use commands like “Bit Test” you mentioned, or the method Nick describes above in PAC Display, to pull one bit from those 32 or 64 bits that make up your Integer 32 or 64.

To help clarify, could you tell us exactly the variable type you’re starting with and where it’s coming from?

Also, you mention “save the variable as binary form” – if you wanted to display it (like PAC Control’s debugger PSG & I mentioned) you could save it for human viewing in a string (kind of the opposite of what I describe above).

Ultimately, your controller just has a certain number of bytes or bits designated per variable. All data is “binary” (boils down to on/off or 1/0 at the bit level in memory). Normally we don’t display it as 1s and 0s because it would just take up too much space, so for humans, we display it as decimal (what most people are used to) or sometimes hex. But there’s not need to “convert” or “save as binary” unless it’s for the purposes of a human looking at it.

I hope that helps!
-OptoMary

That does help! Thank you OptoMary.

I think I figured out how to go about this from your post and PSG’s email. I’ll use the logical commands Bit ON? and Bit OFF ? to check if a specific bit in a variable is on. There is no need for me to translate decimal to bit. So as I understand it Bit OFF? works like so : IsBitOff( num1, 3), my num1 is, for example, 199, so essentially IsBitOff(199,3) which translates to a 1. Had I used IsBitON(199,3) that value would be 0.

Thank you both OptoMary and nick stephens!