Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 10:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Variable saved as a binary file?
PostPosted: February 17th, 2008, 11:31 pm 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
Hi All
Can anyone help me with this?
I have a variable that contains just a string of 48 0’s and 1’s in text format, and need to covert and save it to a file as just a 6 byte (48 bit) binary packet.

Hope that makes sense!


Any ideas?

Thanks

(Opus 5.5)


Top
 Profile  
 
 Post subject:
PostPosted: February 18th, 2008, 10:41 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
quick reply........you can do the following


var textObj = OpenFile("c:\\ADirectory\\TheFile.AAA")

this will create a text file, with the extension AAA...could be anything.

then chop your 48 bits of data into bytes (MyData)
create a loop to write the bytes to the file.
textObj.WriteLine(MyData).
each run through the loop will write a new line to the file.



This will create a file with 6 lines of 8 bits, however--it will still be a text file so the next application may not like the format??. I'm not sure of the format of a binary file, but you can probably format the file by adding the required control characters when you write each alternate byte---I think a binary file may divide the date into 8 bit chunks by using a '-'?? this can be added into MyData. TheByte+"the control character". The control character may need to be preceded with a \ to escape it---

perhaps the binary file is 3 lines of 16 bits (2X8) with control character between the two bytes---this can still be done using a similar method to above :-)

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject: Thanks…
PostPosted: February 18th, 2008, 3:04 pm 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
Thanks…

But that still only gives me a text file containing the numbers 1’s and 0’s
Opened notepad it looks like this : 100100001001000000010000010100000010100000001010

Which in binary is: 00110001 00110000 00110000 00110001 00110000 00110000 00110000 00110000 00110001 00110000 00110000 00110001 00110000 00110000 00110000 00110000 00110000 00110000 00110000 00110001 00110000 00110000 00110000 00110000 00110000 00110001 00110000 00110001 00110000 00110000 00110000 00110000 00110000 00110000 00110001 00110000 00110001 00110000 00110000 00110000 00110000 00110000 00110000 00110000 00110001 00110000 00110001 00110000, because it in text format.

If I could write that string to a file as a pure 48bit binary packet it would look like


Top
 Profile  
 
 Post subject:
PostPosted: February 18th, 2008, 4:14 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
OK I didn't understand you wanted to pipe the data direct to the serial port. I use TextPad and it saw it as a binary file.

How will you send the data to the serial port?
Is there an option for a parallel input??


Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 18th, 2008, 6:52 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
a possible option may be to use Opus to create a file then use the command line to run a batch file which copies the file to the serial port.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 18th, 2008, 8:32 pm 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
Thanks Sandy

Getting the file to the com port is the easy bit – I just use the ‘copy disk file’ action on a button and direct it to com1: instead of c:/directory/

It’s a shame that Opus doesn’t have a ‘write string to serial port’ action. It lets it down as controlling external devices is now such an important area of multimedia.

My workaround is to generate the control codes in a hex editor, saved onto the harddrive and then opus can send them out of the com port as necessary. What I’m trying to do now is get opus to generate the control files ‘on the fly’ rather than being pre made by hand. I’ve managed to generate strings of 48bits (0 and 1) in the right order and save it to a variable <FinalBinOutput> but can’t see how to convert that into a “binary” file (rather than a text file) that the control board understands.


Top
 Profile  
 
 Post subject:
PostPosted: February 18th, 2008, 10:01 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Hi Phil,
There can't be many people who use the serial port any more. Being an Electronics Engineer, I'm very interested in what you are doing.
You have opus 5.5 :-) Did you realise that version 6 has the ability to call DLL's, which is a huge benefit if you want to talk to the outside world....much more versatile than just writing to the serial port.

So with V6 and a USB controller such as the Velleman DMX controller---doing what you are trying to do should be easy(famous last words!!)
I create a lot of software using a USB interface card---that's why I was asking about the parallel option. 8 bit parallel output.

So if you are not on a budget. I would recommend a V6 upgrade and get a Velleman DMX controller.

If I understand you correctly, you save the control codes in files, which are sent to the serial port
So what you need to do is find the ASCII characters which will give you the correct bit pattern?? or a way of creating them....needs some more thought :-)

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 19th, 2008, 12:04 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
More thought later---probably won't work, but worth a try

You can use the following undocumented script (thanks to Mackavi)


String.fromCharCode(MyChar).

What you need to create is a binary file with the correct binary pattern to control the Serial port. Each 8 bits has a decimal value 0-255, so String.fromCharCode(MyChar) where MyChar is 0 to 255 which has binary value 00000000 to 11111111 will insert characters in the file which has a binary equivalent.


so if you know the binary pattern to send to the serial port, you assemble it in Opus????....hope you can see what I'm trying to do :-)

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 19th, 2008, 12:40 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
attached is a file I created using Opus.

I created a file

textObj = OpenFile("c:\\TheDir\\consumption.bin")
then ran the function.

Code:
function SendData()
{
      for(var i=0;i<=255;i++)
          {
            MyData=(String.fromCharCode(i))
            textObj.Write(MyData)
            wait(.2)
            Debug.trace(MyData+"  "+i+"\n")
          }
}


So it simply ran round a loop, 0 to 255 and wrote the ASCII char to file. The debug just shows what's happening.

Opened in a binary viewer, the file comprises 256 bytes 00000000 to 11111111. So you should be able to use this to construct your control files.



hope it works


Sandy


You do not have the required permissions to view the files attached to this post.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 19th, 2008, 11:34 am 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
Thanks Sandy

I was trying to make some sort of ‘look-up’ table to replace each 8 bit of data, or the dec code, with it’s text equivalent but it looks like the first 32 text characters are control functions i.e. NUL, BEL, ACK etc and wont ‘print’ or be recognised by opus. But then again not very good at scripting!!!

I’ll keep trying

I did look into the DMX controller, but that was a bit of over kill and expensive for what we are doing. We are only lighting LED’s (star brights) @ 5v 200ma.
The boards I use have 32 channels each and can have 255 boards. We have 26 boards switching 768 led’s and 12 fibre optic projectors (via relays).
This is all installed within a 1:75 scale architectural model 10m x 4m, for a new development in west London and will be installed in the sales suite / show home. Each apartment has at least 1 led in it that will light when a potential buyer selects that apartment from the opus presentation (on 32” touch screens). Boards also control the room lighting and window blinds. Clients can also print out apartment details/cost etc from opus.


Thanks for all your help

Phil


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2008, 9:31 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Hi Phil,
Sounds like a fascinating project!! sorry for not responding sooner, but my Internet supplier was down for 2 days!!!

Can you send me a file which you know works and I will try to create it using opus.

The script 'should' have worked---in theory, because it has the ability to create all 256 ASCII characters, including 0 to 32 which are the control characters. They won't be displayed, but they should be inserted in the file. The file I included in my last post had all 256 codes inserted, if you looked at the file in a binary editor, you could see all 256 codes 00000000 to 11111111.




I need to understand what a block of data looks like. can you send me a string of ASCII characters you need to control a single LED.....as if a customer had selected an apartment.

I will try to create a 'binary' file with the ASCII codes inserted.

What driver boards do you use just now to drive the LED's.
How many LEDs will be illuminated at the same time??? or is it cumulative to show how many apartments have been 'taken'?


Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2008, 12:38 pm 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
Hi Sandy

Attached a file that if copied to the serial port will turn on led’s 32, 30, 28, 19, 12, 6, 2 on board no 19.
In binary it looks like:
000100111010100000000100000010000010001000000001

First 8 bits control the board no. 00010011
Next 4 bytes control the LED channels 4 to 1 10101000 00000100 00001000 00100010
Last byte is the on/timer command 00000001

As Hex:

13 A8 04 08 22 01

As ASCII Code:

019 168 004 008 034 001


I’m generating variables in binary <FinalBinOutput>

and ASCII code form <BoardNumbera><Bank4a><Bank3a><Bank2a><Bank1a><Timera>



There are a few times when all the led’s and projectors are on at the same time, drawing something like 220 amps!

It hums a bit when we do that! :shock:

Regards


Phil


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2008, 1:15 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
can you e-mail the file--I can't save it from the board, only view it and it opens in notepad. I want to open it in a binary editor.

I'm sure it should be possible to recreate the file from opus.
Do you normally just use text files???

The project sounds very interesting---220A!! how many PSU's are you using?? When it hums---is it a tune you recognise???? :-)

If this file works, then it should be easy to create functions to turn on lamps---how does the selection operate???

A function could be created like......


function LightALED(BoardNumbera,Bank4a,Bank3a,Bank2a,Bank1a,Timera)
{
the script
}

to call the script, you would use

LightALED(3,168,4,8,34,1)


what's the coding of the LED channels???

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2008, 1:27 pm 
Offline

Joined: August 31st, 2006, 3:21 pm
Posts: 10
Location: Bristol & London
My very simple program for generating the codes!! Will make it pretty after it works!


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject:
PostPosted: February 21st, 2008, 2:52 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
here is a test pub.
it is very basic

when you press the button. It will create a file in C:\Energy\Binary.txt


the file should have 19, 168, 4, 8, 34, 1 in binary.

each time you run it, you have to delete the file, otherwise it will append the next line to the file.
I just used scripting just now, but there's an action to over-write the file contents

I just want to confirm that binary.txt will control your LEDs.


It looks identical to your file when opened in a binary editor.


If this works, then the solution to your problem is quite easy and you will be able to build an amazing system---you could sequence the lights, do all kinds of things with it !!!

What is the total conversion time for the board. ie how quickly can you switch a LED on, then off??

Sandy

Sandy


You do not have the required permissions to view the files attached to this post.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group