Page 1 of 1

Sending data to the serial port in OSX via PHP (new subject)

Posted: Tue Oct 11, 2005 12:16 am
by robster
Hi all,

The new till arrived today! Very exciting! It opens on ANY data being sent to the com1 port (where it's connected).

The test machine is windows, the production machine is osx.

Is there a PHP command that I can use to access (send data) to the com port that is cross platform?
The settings are: MODE COM1: BAUD=9600 PARITY=N DATA=8 STOP=1

It's all ready to go, I just have to fill in the blanks in a function called open_till() ;)



Any advice, links or discussion appreciated.

Rob

Posted: Tue Oct 11, 2005 12:26 am
by robster
cancel that!

Code: Select all

//*****************
	//Pos OPEN THE TILL
	//*****************
	function pos_open_till()
	{
	`mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
	   $fp = fopen ("COM1:", "w+");
	   if (!$fp) {
		   echo "Uh-oh. Port not opened.";
	   } else {
		   $e = chr(27);
		   $string  = ""; //don't need to send anything, it's just a null string
		   $string .= $e;
		   fputs ($fp, $string );
		   fclose ($fp);

	   	 //echo "till open<br>";
	   }
	}
I found fopen function, very nice indeed.

I have a real life object (a till) that now opens via my php script, it's SO damn cool, you have no idea how sad that sounds, but it's excellent to see a real life object respond to my code ;)

Rob

Posted: Tue Oct 11, 2005 8:05 am
by infolock
i'm assuming you are writing a POS system. been there, done that, wrote the book. the app is not hard at all, but like you, the problem resided in opening the drawer. there is actually a quicker way (if i can find the code) of doing this. I'll try to find it. anyways, wether you are or are not writing a pos, you should look into printing on reciept machines if you want to seriously begin pulling your brains out. it's insane. anyways, have fun

Posted: Tue Oct 11, 2005 11:28 pm
by robster
mmm, seems you're right!
It opens a treat on the xp machine, ding, till opens, very fun stuff (yes, it's for a POS system).

I took it to the hair salon and installed it on the mac (running OSX 10.2 I believe) and the standard php and mysql install that comes with (or that you install) and it won't open the till.

Here's the lowdown:

The mac has no serial port.
To overcome this a usb2serial adapter was purchased, installed and is running
To test this, I connected the till and told the mac via networking that the modem was infact a null modem cable connected to com1
I tried to connect via this 'modem' and the till opened. Bingo, it works.

I then go to my code and try and open till, and it does NOT open.

I check the settings (and here's where some mac advice could come in handy), it turns out the serial port installs itself in networks under an entry called USBSERIAL.

Looking in the /DEV/ folder on the mac there is an entry now called tty.usbserial.

I've tried changing the code above so many variations of this:

Code: Select all

//*****************
    //Pos OPEN THE TILL
    //*****************
    function pos_open_till()
    {
    `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
       $fp = fopen ("USBSERIAL:", "w+");
       if (!$fp) {
           echo "Uh-oh. Port not opened.";
       } else {
           $e = chr(27);
           $string  = ""; //don't need to send anything, it's just a null string
           $string .= $e;
           fputs ($fp, $string );
           fclose ($fp);

            //echo "till open<br>";
       }
    }
or

Code: Select all

//*****************
    //Pos OPEN THE TILL
    //*****************
    function pos_open_till()
    {
    `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
       $fp = fopen ("SERIAL:", "w+");
       if (!$fp) {
           echo "Uh-oh. Port not opened.";
       } else {
           $e = chr(27);
           $string  = ""; //don't need to send anything, it's just a null string
           $string .= $e;
           fputs ($fp, $string );
           fclose ($fp);

            //echo "till open<br>";
       }
    }
etc etc but to no avail.


I'm really sort of, stumped. Come to an end of my ideas :( I expected a few hickups, but this is really a bit of a downer. I'll get there though, but it seems I will need the advice of someone who can point me in the right direction.

So yes please, any advice appreciated.

:)

Rob

Posted: Wed Oct 12, 2005 12:33 am
by robster
I have been looking around and it seems an option may be to open the port via applescript. (hence the subject change for this thread).

First of all I know not how to do this but will investigate.
Secondly, can I call an applescript from PHP on OSX?

Thanks again,

Rob

Posted: Wed Oct 12, 2005 10:34 am
by infolock
unfortunately, i'm only a windows guy so i don't really know. havne't had time to find the eject script i was telling you about, but i'll find it

Posted: Wed Oct 12, 2005 12:48 pm
by Chris Corbyn
robster wrote:I have been looking around and it seems an option may be to open the port via applescript. (hence the subject change for this thread).

First of all I know not how to do this but will investigate.
Secondly, can I call an applescript from PHP on OSX?

Thanks again,

Rob
If an applescript is anything like a bash script in *nix I guess you can just use the exec() or system() commands (or use backticks like you did above). Should work ;)

I have no mac experience at all though :?

Posted: Wed Oct 12, 2005 12:51 pm
by chrys
*blink*

I never knew you could use PHP to communicate with a computer's hardware... isn't this dangerous?

Where can I read more about this?

Posted: Wed Oct 12, 2005 1:30 pm
by Chris Corbyn
chrys wrote:*blink*

I never knew you could use PHP to communicate with a computer's hardware... isn't this dangerous?
Only as dangerous as the person developing it ;)

Posted: Wed Oct 12, 2005 1:32 pm
by redmonkey
I was playing around with something similar today, I was using the 'talk' and 'wall' commands, which allows you to access various I/O ports.

Posted: Wed Oct 12, 2005 4:48 pm
by robster
could you describe that a little more?

Thanks :)


(and yes, with me doing it, it's dangerous! :twisted: )

Rob