USB >>> Serial Port >>> Test >>> WinXP CMD

slimplynth

Senior Member
Evenin' all... the below problem is in relation to the PHP >>> Picaxe thread I stated earlier this week.

Using the command prompt in WinXP, to send serial data to a Picaxe 18M2 (via USB >>> AXE027.)

Code:
C:\> mode com11:9600,n,8,1

C:\> echo 49 > com11:
Executing the first line above tells me that DTR & RTS are both on.

I can switch these off...

C:\> mode com11: dtr = off but by default this sets the parity to even and the data bit=7.

(I'm unable to set all parameters in a single command line however... i've tried numerous combinations and googled like mad for an example)

When the picaxe receives any serial data it should flash 4 leds. (This occurs in the PE terminal/hyperterminal but not from the command line.

I was wondering if dtr & rts being on are causing the problem.. i also wondered if this would be a problem unique to the AXE027.. i.e. would the two lines of command prompt above work with a regular 9 pin serial port :confused::confused::confused::confused:

Does anyone have:

1) a small calibre gun to put me out of my misery quicker than this monkey like tippy tappying will.

2) the cmd line necessary to configure the com port in one line so that dtr & rts are turned off on the same line (not completely sure if this is possible.

3).. nah just a small calibre gun will do.

Thanks

Picaxe Code:

Code:
Setfreq M8
Symbol LED_Pause = 100

Main:

b0 = 0

Serrxd b0

If b0>0 Then Goto LED_Flash

Goto Main

LED_Flash:

For b1 = 1 To 10
High B.4
Pause LED_Pause
High B.5
Pause LED_Pause
High B.6
Pause LED_Pause
High B.7
Pause LED_Pause
Low B.4,B.5,B.6,B.7
Pause LED_Pause
Next b1

Goto Main
 

Attachments

Minifig666

Senior Member
You cold use the serial interface provided with the CLI compiler.
Oh, and Cdngunner, can we have that 1/3 please? This is something I've been trying to do too.
 

MPep

Senior Member
Would it help if you connected as a Null Modem, ie : tie 1 & 4 & 6 together, and 7 & 8 together at the PICAXE end? Just a thought.
This would take care of handshaking issues that you may be having.

Sorry, haven't read the PHP post as I know absolutely nothing about it.
 

hippy

Technical Support
Staff member
I don't recall DTR or RTS should affect a download via an AXE027 ( or anything else ) using the standard three-wire, 0V/TX/RX, download interface.

The problem is probably in "echo 49 > com11:" that sends two characters to COM11. Actually, more likely five characters; "4", "9", "<space>", "<CR>" then "<LF>".

I'd say get out of the habit of trying to use ASCII character values and simply send a single printable ASCII character.

That said, it should still have worked ... so perhaps it's that MS-DOS / Command Prompt isn't interfacing correctly with non-physical ports, ports other than COM1:-COM4: ...

When I do "echo 49 > com11:" this creates a "com11." file in the directory I'm in when the command is issued. And surprise, it's five bytes long. So looks like re-direction to non-physical ports does not work.

What you need is a command line program which can replace "echo" and can access non-physical COM ports. Got to go out now but I'll think about that.
 

Minifig666

Senior Member
Have you tried it under DOSBox? It has support for virtual COM ports and will let you implement the older commands. Unfortunately I haven't tried it myself.
 

slimplynth

Senior Member
thanks Hippy, Minifig...

I couldn't determine what was happening on sending the echo command.. but googling threw up a few likely culprits.. virtual com port or ftdi... so thanks for that Hippy.

The reason I was trying to do this was because in the PHP code I have the following gets executed...

Code:
`mode COM11: BAUD=9600 PARITY=N data=8 stop=1 xon=none`;
if the echo won't work in the command prompt the above will never work in PHP.

I know what I need to do next.. I have to get to grips with PEAR/PYRUS and then the FIO commands.. I just wanted to avoid that this early on in my php learnings.

Thanks again, case closed.
 

lbenson

Senior Member
Can you not do something like

$fh = fopen("COM11", 'w') or die("Can't open COM11");

and then write to $fh?
 

hippy

Technical Support
Staff member
I've never used PHP so can't really help with that side of things. It seems you're up against similar issues when using a web-server to invoke a Perl CGI program to communicate with serial ports, you're limited to making shell / exec calls out of Perl or using some Perl / Perl Module calls to access serial ports directly ( or equally using shell / exec in its bowels ). I've never really felt comfortable with that, and have never got it to work reliably.

My solution was to write my own web server in Visual Basic. That parsed the 'HTML files' requested and filled in 'markers' for data from a PICAXE and/or passed data to the PICAXE. Effectively a PHP server but having its own built in access to serial ports which I could control exactly how I needed. No need for shelling or running other command line programs. That's a bit more complicated and I don't have any source code to hand which would be useful to you but is IMO the best solution.

A half-way solution may be to handle things as a traditional web server would with CGI. You invoke the CGI executable which is your aplication which can control serial ports directly. Not as good IMO, but you would only need to write the CGI application not a complete web server. There are however potential queueing issues so that may dicatate a client-server solution for CGI handling is best, and that to me suggests a full web-server is actually easier as it can include queueing more easily within itself. There's also the question of how to get the web-server to use / invoke your CGI application, the ease of which will depend on web server chosen.

My decision was based on a DIY web server meaning I had total control over what it could do and how, and the effort of that outweighed the difficulties of making alternative solutions do what I wanted ( even avoided having to think 'how to' ). If it's a programming language you are familiar with, once you have a web server dishing-up files from disk, it should be fairly easy to bolt the serial interface on top.

In effect that's using a PC and VB to create a PICAXE.Net or SitePlayer server which may also be worth looking at and there may be other solutions.
 

slimplynth

Senior Member
@Ibenson: Cheers, I have tried many variations on that themed from the examples on the web, for the Ard**** but it's as if the data just disappears into thin air - that's why i changed the serrxd in the code above... if b0>0 then flash some lights... i think hippy has nailed the problem on the head with the virtual ports... even then I couldn't actually prove it.

@Hippy: Thanks for the explanation... re. economics time >>> effort >>>gain; I was looking at the PNS today again working out what the VAT increase will mean :0( cost is one part of it. I am a skin flint - my house needed plastering so i went on a plastering course.. I just like doing things myself and like you said with the DIY server - you have complete control.

I pondered what it meant to buy the PNS and what control others have over that system and i didn't like the doubt, though I can see the obvious advantage in learning something new that will be relatively pain free. I had to explain on a PHP forum that I am probably trying to run before I can walk. I'll invest in a decent book or two. It may take a couple of years to bring it all together but I will one day be able to exercise full control over my house's lighting etc via the web and an army of picaxe drones :0)
 

hippy

Technical Support
Staff member
@ slimplynth ( and anyone else interested ) : I've been meaning to rewrite my VB6 web server for a while and you encouraged me to strip that right back and "do it properly" - or at least get to a better foundation than the mess it had become with hacking on this and that.

I've now got a simple web server which can serve up pages and talk to serial ports. It's not totally robust but may be useful for what you are doing. For example, entering the following in the browser address bar -

http://172.16.0.10:81/hello.axe

With the following C:\Picaxe\hello.axe file ...

Code:
COM1:4800,N,8,1
Hello There
COM2:9600,N,8,1
Wake Up!
<html>
  <body>
    Sent "Hello There" to COM1:4800,N,8,1<br>
    Sent "Wake Up!" to COM2:9600,N,8,1
  </body>
</html>
That will display the HTML and, does what it says; sends "Hello There<CR><LF>" out on COM1 at 4800 baud and sends "Wake Up!<CR><LF>" out on COM2 at 9600 baud.

It should be convertable to VB.Net and it I'm working on extending it to also receive data from a PICAXE in response to what's sent. You can also simply run the executable; settings and file paths are configurable via the registry.

If anyone's interested I can look at packaging that up and posting it.
 

slimplynth

Senior Member
Cheers Hippy, a tempting offer but i'm going to stick at the php for a while (i keep starting things and never finishing :) )

Definitely a nice thing to have for the future though..

Hope Dippy spotted that spelling... not like the below on the Argos site (comments pg 2)
http://www.argos.co.uk/static/Product/partNumber/7112922/Trail/searchtext>DREMEL.htmhttp://www.argos.co.uk/static/Product/partNumber/7112922/Trail/searchtext>DREMEL.htm page

Individual reviews
23 February 2010
Dremel 300
By **** from Southport
Overall Rating5 StarsExcellent
Recommend to a friend? Yes
"A very good tool, would definately recommend"
 

hippy

Technical Support
Staff member
Cheers Hippy, a tempting offer but i'm going to stick at the php for a while (i keep starting things and never finishing :) )
No worries, whatever you feel best. I've attached the source and executables if you do want to have a play, to prove it can work (COM1-COM16 only as that's a limit of VB6 ). It now includes replies from the PICAXE. Tested with 20X2 but should be modifiable for others.

Download, rename as .ZIP, extract etc. There may be some missing files (.OCX) so if anyone has problems shout. All files needed will be placed in the one directory, can be anywhere, I'd suggest C:\WebServe to start with. The MsWinSck.Ocx may need moving to C:\Windows\System32, but try without first.

Download to the PICAXE ( Report.Bas ) ...

Code:
Do
  SerRxd( "Report" ), b13
  Select Case b13
    Case "0" : SerTxd( "w0=", #w0, CR, LF ) : inc w0
    Case "1" : SerTxd( "w1=", #w1, CR, LF ) : inc w1
    Case "2" : SerTxd( "w2=", #w2, CR, LF ) : inc w2
    Else     : SerTxd( "w", b13, "=Unknown", CR, LF )
  End Select
Loop
There are four Report0.Htp- Report3.Htpfiles which communicate with the PICAXE via the web server ( was .AXE in this version )...

Code:
Tx:COM1:9600=Report0
Rx:COM1:9600
<html>
<body>
Sent "<!--SENT-->" to <!--PORT-->:<!--BAUD-->,<!--MODE--><br>
Reply was ... <!--REPLY-->
</body>
</html>
You will probably need to change the COM1:9600 to the port you are using and to match the SERRXD/SERTXD baud rate in all four files, Report0.Axe - Report3.Axe

Now run C:\WebServe\WebServe.Exe

From a browser enter http://127.0.0.1/report0.htp

You should see ...

Code:
Sent "Report0" to COM1:9600,N,8,1
Reply was ... w0=0
For every subsequent http://127.0.0.1/report0.htp you should see the w0=X number increase by one.

Enter http://127.0.0.1/report1.htp and you'll see w1=X results incrementing.

It runs in the system tray with an animated icon. If minimised then right click in the system tray and restore or exit.

See later posts for download, source code and executable.
 
Last edited:

slimplynth

Senior Member
Cheers I think I will have a go, I wasted probably half a working week with no success on the php... it'd be stupid to not look at a proven/tested example.

Thanks Hippy
 

hippy

Technical Support
Staff member
Latest version attached. Tarted up and refined with a few changes ...

Settings now stored in a .INI file which makes it easier to change things. To run on a different port change -

[HttpServer] Port = 80

Change of file extension from .AXE to .HTP ( Hyper-Text for PICAXE ). Change the following settings in the .INI file to use Report*.Htp and match to your setup -

[ComPorts] Port = COM1
[ComBauds] Baud = 9600

Better handling of serial including timeout on receive so the server doesn't lock up. Plus the ability to send and receive via the URL itself. Look in Report*.Htp for the Tx: and Rx: lines to see how to sned and initiate comms. The <!--REPLY--> etc gets replaced by what was received.

Once WebServe is running running, the URL's to use are slightly different ...

http://127.0.0.1/report0.htp
http://127.0.0.1/report1.htp
http://127.0.0.1/report2.htp
http://127.0.0.1/report3.htp

http://127.0.0.1/reportx.htp?tx:port:baud=Report0&rx
http://127.0.0.1/reportx.htp?tx:port:baud=Report1&rx
http://127.0.0.1/reportx.htp?tx:port:baud=Report2&rx
http://127.0.0.1/reportx.htp?tx:port:baud=Report3&rx

I note a few people had downloaded the previous version - Anything to report ? Did it work ? Any help needed ?

This is probably as far as I'm going to go with this as it seems to the job. Can send to one or more PICAXE, can send to a PICAXE and receive a reply. Replies can be parsed and formatted using javascript etc. There's a couple of places some error trapping wouldn't go amiss but this is it for now.
 

Attachments

Last edited:

julianE

Senior Member
I note a few people had downloaded the previous version - Anything to report ? Did it work ? Any help needed ?
Does not fully work for me. It may not be your server that's at issue.
I am using what seems to be the cursed chip, 18M2. I do have plenty of 20X2's so i can try using it tomorrow.
If I use the picaxe terminal in the picaxe editor and I send Reports0 I do get a proper response from the 18M2. If i try it with Hyperterminal it does not work so it might be something with my PC.

To troubleshoot, I changed the 18M2 program to bare bones,

Do

SerTxd( "w0=", #b1, CR, LF ) : inc b1

Loop

I can see numbers flying by in Hyperterminal and if I use the web server I also get a response so it's something with the transmit portion.
 

julianE

Senior Member
I did get the Hyperterminal to work, needed to reboot the machine,
if I send Report followed by a number I receive a proper response from 18M2:

w0=3
w3=Unknown
w2=0

sadly this is what I get from the Web Server:

Sent "Report0" to "COM1:4800,N,8,1"
Reply was ... <No Reply>

I went and hooked up the program cables between two different PC's and fired up a Hyperterminal on the machine that was taking place of the 18M2, worked perfect, the hyperterminal showed Report0 and the Browser showed a correct response from the Web Server, whatever i typed in the Hyperterm after i received the message Report0. So it seems that the Web Server Hippy wrote is fine and dandy, the 18M2 works right when attached to hyperterminal but does not communicate correctly with the Web Server, does not seem to be getting messages from the Web Server.

I will try a 20X2 after some sleep, getting very late.
 

julianE

Senior Member
20X2 Works

I tried the Web Server with a 20X2 and it does work.
If I send too many requests, like 7 in a row, the Web Server crashes with a

Run Time Error '40006':
Wrong protocol or connection state for the requested transaction or request.

I must say it's rather smooth when it does work, better then other implementations I've tried.
 

hippy

Technical Support
Staff member
I've fixed a couple of bugs in the server including I recall that 'wrong protocol' crash. I'll look at realeasing updated code. I'll also try and test with an 18M2.
 

julianE

Senior Member
I've fixed a couple of bugs in the server including I recall that 'wrong protocol' crash. I'll look at realeasing updated code. I'll also try and test with an 18M2.
Thanks Hippy, I am glad you are continuing development. I tried opening your code in VB6 but must be doing something wrong since I could not open it. Looking forward to the next iteration of the Web Server.
 
Top