Sending bytes from Spinneret to Visual Basic

I been working on finding a way to transfer bytes from the Spinneret to VB without having to depend on HTML. I have some experience with programming VB from the VB 5.0 back in time but have very little experience with VB.NET or -net related programming. But so far I have made an application where I can receive and display HTML-based information on VB just like a browser. My spinneret is currently loaded with a modified version of Mike's HTMLGraph.spin. (Just added my own html-code and a few additions to the ParseResource-method).
What I would like to do is to be able to receive data like single bytes or packets of bytes from the Spinneret into VB through the Internet.
Like if I send the request from VB: 10.0.0.130:5000/sendData, the Spinneret should respond with sending the byte or the chain of bytes I want, clean without any html-tags.
I really believe this is a quite simple task but I have to admit I'm stuck. No more ideas on how.
I do think I need another addition to the ParseResource but I have no ideas on how it should look like.
So here I come creepin', asking for a good advice or a little snippet that can push me back on the track again!
Spinneret: HTMLGraph.spin
VB: Visual Basic 2010 Express
What I would like to do is to be able to receive data like single bytes or packets of bytes from the Spinneret into VB through the Internet.
Like if I send the request from VB: 10.0.0.130:5000/sendData, the Spinneret should respond with sending the byte or the chain of bytes I want, clean without any html-tags.
I really believe this is a quite simple task but I have to admit I'm stuck. No more ideas on how.
I do think I need another addition to the ParseResource but I have no ideas on how it should look like.
So here I come creepin', asking for a good advice or a little snippet that can push me back on the track again!
Spinneret: HTMLGraph.spin
VB: Visual Basic 2010 Express
Comments
Here: http://forums.parallax.com/showthread.php/144918-VB.net-and-the-Spinneret
I originally designed the Spinneret libraries for RESTful services. However, the community for some reason latched onto HTML. I guess I need to build another example.
http://code.google.com/p/propeller-w5200-driver/downloads/list
Make sure you get the zip that goes with the Spinneret => WebServer_W5100_RTC - Archive [Date 2013.02.20 Time 07.00].zip <= if you have a Spinneret. It will also work with the yet to be released WizNet fo5200 for Quick Start.
Unzip the attached .NET C# project and open the project in VS 2010. If you do not have Visual Studio or don't feel like installing VS for C# then simply drill into the folder HttpClientDemo\bin\Release.
You must update the app.config to point to your Spinneret IP address.
<applicationSettings> <HttpClientDemo.Properties.Settings> <setting name="serviceUrl" serializeAs="String"> <value>http://[B]192.168.1.110[/B]/pinstate.xml?led={0}&value={1}</value> </setting> </HttpClientDemo.Properties.Settings> </applicationSettings>
Execute (double click) HttpClientDemo.exe or run the project. It's pretty simple, turn LED 23 on and off. Play with the PIN and/or value textboxes.
The .NET code is open and free - happy programming.
Not much experience with C# here but I do have the Visual Studio with both VB and C# installed so maybe this is the time to convert, hehe. Should not be a too much of a difference.
Anyway, I will check out this tonight when back again from work.
Thanks again!
Awesome!
Repeating over and over... really do appreciate your help!
Use an xsl stylesheet for the xml. I use it all the time.
Here is my additions or modifications to the .spin file:
In DAT section:
xmlPessmar byte "<root>", CR, LF, " <Incoming>" incoming byte $30, $30, $30,"</Incoming>", CR, LF,"<Returning>" returning byte $30, $30, $30, "</Returning>" , CR, LF, { } "</root>", 0
In PRI RenderDynamic(id):
if(strcomp(req.GetFileName, string("pessmar.xml"))) BuildValue( req.Get(string("incoming")) ) BuildAndSendHeader(id, -1) sock[id].Send(@xmlPessmar, strsize(@xmlPessmar)) return true
Added methode:
PRI BuildValue(strvalue) | value , newval value := StrToBase(strvalue, 10) value:= value*2 pst.str(string("Incoming: ")) pst.str(strvalue) if(strsize(strvalue) > 1) bytemove(@incoming,strvalue, 3) else byte[@incoming] := $30 byte[@incoming][1] := byte[strvalue] newval:= dec(value) pst.str(string(" Returning: ")) pst.str(newval) if(strsize(newval) > 1) bytemove(@returning,newval, 3) else byte[@returning] := $30 byte[@returning][1] := byte[newval]
So if I type http://la3usa.com:5000/pessmar.xml/incoming/444
I receive this from the spinneret:
<root>
<Incoming>444</Incoming>
<Returning>888</Returning>
</root>
which is correct, but if I type things like http://la3usa.com:5000/pessmar.xml/incoming/45
I recieve this:
<root>
<Incoming>45
..see, no returning value at all. In VB I also get an error message.
Sorry for all this strange behaviors here but cant help for it!
You could also use a space character; ie $34, $35, $20. Regardless, you must update the spin source because a zero terminator in a text based protocol messes everything up.
PRI BuildPinStateXml(strpin, strvalue) | pin, value, state, dir pin := StrToBase(strpin, 10) value := StrToBase(strvalue, 10) SetPinState(pin, value) state := ReadPinState(pin) 'Write the pin number to the XML doc PadLeft(@pinNum, strpin, 3, "0") 'Write the pin value value := Dec(ReadPinState(pin)) PadLeft(@pinState, value, 3, "0") 'Write Pin direction dir := Dec(ReadDirState(pin)) PadLeft(@pinDir, dir, 3, "0") PRI PadLeft(dest, source, len, padChar) 'Fill the destination buffer with the padding char if(strsize(source) < len) bytefill(dest, padChar, len) 'Write the string offset from the start of the destination buffer bytemove(dest+len-strsize(source), source, strsize(source)) PRI PadRight(dest, source, len, padChar) 'Fill the destination buffer with the padding char if(strsize(source) < len) bytefill(dest, padChar, len) 'Write to the start of the destination buffer bytemove(dest, source, strsize(source))
What's still confuses me a little is the hexadecimals, like in line 70 in your original code:
pinNum byte $30, $30, "</pin>", CR, LF, " <value>"
I figure out they are some kind of placeholders and in this case they mean "0", "0". But I cant find a good explanation in the Propeller Manual (DAT-section) and it seems I can use any number here, also $32 or $33 and still get the same result. But I guess I have to stay in the range of $30- $39, anything else will just print the actual ascii-sign, right?