473,811 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pack and unpack

158 New Member
Ok what i am trying to do with my script i send a poll and receive a reply and read that reply. I have the Poll work properly but what i need help with is trying to convert the reply from ascii to regular text.

My reply consist of 30 different variables and i need them to be separated. my code so far is.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. print "Content-type:text/html\n\n";
  4. use IO::Socket;
  5.  
  6. #Poll
  7. my $header = 'Art-Net';
  8. my $space = ' ';
  9. my $Prover = chr(0x0e);
  10. my $filler = chr(0x00);
  11. my $ttm = chr(0x02);
  12. my $ID = $header.$filler;
  13.  
  14. my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
  15.  
  16.  
  17. #My Reply.
  18. my $T_ArtPollReply = pack("A8 S C C C C C C C C C S C18 C64 C64 C C C C C C C C C C C C C C C6 C32",
  19.     $ID,
  20.     $OpCode,
  21.     $BoxAddr,
  22.     $VersionInfoH,
  23.     $VersionInfo,
  24.     $SubSwitchH,
  25.     $SubSwitch,
  26.     $OemH,
  27.     $Oem,
  28.     $UbeaVersion,
  29.     $Status,
  30.     $EstaMan,
  31.     $ShortName,
  32.     $LongName,
  33.     $NodeReport,
  34.     $NumPortsH,
  35.     $NumPorts,
  36.     $PortTypes,
  37.     $GoodInput,
  38.     $GoodOutput,
  39.     $Swin,
  40.     $Swout,
  41.     $SwVideo,
  42.     $SwMacro,
  43.     $SwRemote,
  44.     $Spare1,
  45.     $Spare2,
  46.     $Spare3,
  47.     $Style,
  48.     $Mac,
  49.     $Filler,
  50. );
  51.  
  52. $Node_Ip = '2.0.0.1';
  53.  
  54. my $poll = IO::Socket::INET->new(
  55.     PeerAddr    => $Node_Ip,
  56.     PeerPort    => "6454",
  57.     Proto        => "udp",
  58.     LocalPort    => "6454",
  59. );
  60.  
  61. sub ArtPoll {
  62.     $poll->send($ArtPoll);
  63.     print "ArtPoll sent.\n<hr>";
  64.  
  65.     sub Reply {
  66.         $poll->recv($T_ArtPollReply,250);
  67.         print $T_ArtPollReply;
  68.     }
  69.     &Reply;
  70. }
  71.  
  72. &ArtPoll;
  73.  
When i run it i try to print the reply but i get[HTML]<br>[/HTML] Art-Net??!??6? ??ÒLATest1??? ??????????Test Node ??????????????? ??????????????? ??????????????? ?????????#0001 [0019] Power On Tests Pass??????????? ??????????????? ???????€€????? ?€€?????????? ??????¦?

i know i have to do something with unpack or something but not sure if some one could help me out it would be very helpful.
Jun 13 '07 #1
0 1432

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2323
by: Johannes | last post by:
Hi, I tried to pack eight integer values and one string into one binary string, which I would like to store in a mysql db. I encountered two problems doing this: 1) $this->packed = pack('N8A*', $this->value1, $this->value2, $this->value3, $this->value4, $this->value5, $this->value6, $this->value7, $this->value8, $this->stringvalue);
2
3698
by: Sergey Dorofeev | last post by:
I can use string.unpack if string in struct uses fixed amount of bytes. But is there some extension to struct modue, which allows to unpack zero-terminated string, size of which is unknown? E.g. such struct: long, long, some bytes (string), zero, short, short, short.
4
15611
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
18
7587
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask because I'm trying to refactor working code that is concise: 08 12 34 56 80 00
0
1393
by: Steve | last post by:
Are there any gurus of the pack/unpack world out there that can help me with this one? I have an encrypted string which I'm reading from a zipped file. It was written using pack ( "la" . strlen (encrypted), strlen (encrypted), strlen (encrypted)) most of the time, it decrypts correctly when I unpack as...
5
1744
by: andmarti | last post by:
If I build a strict with: import struct print struck.pack ('i', 1) it returns a '\n'. What's wrong with it??? :( --
1
8001
by: praveen0437 | last post by:
hi i know about format argument in pack and unpack like b h i etc but in some cases i am getting < or = symbols along with them what does they signifies for example struct.pack( "<cI", 'n', var1 )
5
7370
by: tmp123 | last post by:
Hello, Thanks for your time. After review the "struct" documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte + zero terminated string + zero terminated string + byte, it seems no possible to unpack it using "struct".
1
3159
by: joe shoemaker | last post by:
If you have the following: data = unpack('>L', sock.recv(4)) Does this line of code means that incoming data is big endian and unpack it to endianess of local machine? If local machine is little endian, then big endian is automatically converted to little endian format? thank you.
0
9730
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.