Author Topic: Can I use a usb port as a com-port?  (Read 3387 times)

Wim Brul

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 28
  • Posts: 130
    • View Profile
    • Wim's home page
Re: Can I use a usb port as a com-port?
« Reply #30 on: March 20, 2017, 03:43:17 pm »
Hallo Roberto,

I have added the vendor specific requests that seem to be required.

Code: [Select]
/* add UsbLoadFuncs */
rc = RxFuncAdd('UsbLoadFuncs','usbcalls','UsbLoadFuncs')
say '+UsbLoadFuncs(),RC=0x'd2x(rc)
/* invoke UsbLoadFuncs */
rc = ('' <> UsbLoadFuncs())
say '*UsbLoadFuncs(),RC=0x'b2x(rc)
/* drop UsbLoadFuncs */
rc = RxFuncDrop('UsbLoadFuncs')
say '-UsbLoadFuncs(),RC=0x'd2x(rc)

/* invoke RxUsbOpen */
drop Handle /* receives device handle */
EnumDevice=0 /* accept any free device */
idVendor=x2d(067B) /* vendor identifier */
idProduct=x2d(2303) /* product identifier */
bcdDevice=x2d(0300) /* device release number */
rc = RxUsbOpen(Handle,EnumDevice,idVendor,idProduct,bcdDevice)
say '*RxUsbOpen(),RC=0x'd2x(rc)

/* invoke RxUsbDeviceSetConfiguration */
Config=1 /* configuration value to be set */
rc = RxUsbDeviceSetConfiguration(Handle,Config)
say '*RxUsbDeviceSetConfiguration(),RC=0x'd2x(rc)

/* vendor specific initialization */
call VendorGetMagic x2d(8484) x2d(0000)
call VendorSetMagic x2d(0404) x2d(0000)
call VendorGetMagic x2d(8484) x2d(0000)
call VendorGetMagic x2d(8383) x2d(0000)
call VendorGetMagic x2d(8484) x2d(0000)
call VendorSetMagic x2d(0404) x2d(0001)
call VendorGetMagic x2d(8484) x2d(0000)
call VendorGetMagic x2d(8383) x2d(0000)
call VendorSetMagic x2d(0000) x2d(0001)
call VendorSetMagic x2d(0001) x2d(0000)
call VendorSetMagic x2d(0002) x2d(0044)

/* invoke RxUsbCtrlMessage host-to-device */
Data=x2c(80250000 00 00 08) /* 9600,1,N,8 */
RequestType=x2d(21); Request=x2d(20) /* SetLineCoding interface class */
Value=x2d(0000); Index=x2d(0000); drop NumBytes; Timeout=100; /* interface 0 */
rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,NumBytes,Data,Timeout)
say '*RxUsbCtrlMessage(SetLineCoding),RC=0x'd2x(rc)
if (rc = 0) then do
  say ' BaudRate:' c2d(reverse(substr(Data,1,4)))
  say ' StopBits:' c2d(substr(Data,5,1))
  say ' ParyType:' c2d(substr(Data,6,1))
  say ' DataBits:' c2d(substr(Data,7,1))
end

/* invoke RxUsbCtrlMessage device-to-host */
drop Data /* receives string of data bytes read */
RequestType=x2d(A1); Request=x2d(21) /* GetLineCoding interface class */
Value=x2d(0000); Index=x2d(0000); NumBytes=7; Timeout=100; /* interface 0 */
rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,NumBytes,Data,Timeout)
say '*RxUsbCtrlMessage(GetLineCoding),RC=0x'd2x(rc)
if (rc = 0) then do
  say ' BaudRate:' c2d(reverse(substr(Data,1,4)))
  say ' StopBits:' c2d(substr(Data,5,1))
  say ' ParyType:' c2d(substr(Data,6,1))
  say ' DataBits:' c2d(substr(Data,7,1))
end

/* invoke RxUsbBulkWrite */
drop NumBytes /* receives number of data bytes written */
Endpoint=2; AltSetting=0; Data=copies(x2c(50),8); Timeout=8000
rc = RxUsbBulkWrite(Handle,Endpoint,AltSetting,NumBytes,Data,Timeout)
say '*RxUsbBulkWrite(),RC=0x'd2x(rc)

/* invoke RxUsbBulkRead */
drop Data /* receives string of data bytes read */
Endpoint=128+3; AltSetting=0; NumBytes=1; Timeout=8000
rc = RxUsbBulkRead(Handle,Endpoint,AltSetting,NumBytes,Data,Timeout)
say '*RxUsbBulkRead(),RC=0x'd2x(rc)
if (rc = 0) then do
  say ' Data:' c2x(Data)
end

/* invoke RxUsbClose */
rc = RxUsbClose(Handle)
say '*RxUsbClose(),RC=0x'd2x(rc)

/* add UsbDropFuncs */
rc = RxFuncAdd('UsbDropFuncs','usbcalls','UsbdropFuncs')
say '+UsbDropFuncs(),RC=0x'd2x(rc)
/* invoke UsbDropFuncs */
rc = ('' <> UsbDropFuncs())
say '*UsbDropFuncs(),RC=0x'b2x(rc)
/* drop UsbDropFuncs */
rc = RxFuncDrop('UsbDropFuncs')
say '-UsbDropFuncs(),RC=0x'd2x(rc)
return

VendorGetMagic:
parse arg Value Index
/* invoke RxUsbCtrlMessage device-to-host */
RequestType=x2d(C0); Request=x2d(01); drop Data;
rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,1,Data,100);
say '*RxUsbCtrlMessage(VendorGetMagic),RC=0x'd2x(rc);
return

VendorSetMagic:
parse arg Value Index
/* invoke RxUsbCtrlMessage host-to-device */
RequestType=x2d(40); Request=x2d(01); drop NumBytes;
rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,NumBytes,,100);
say '*RxUsbCtrlMessage(VendorSetMagic),RC=0x'd2x(rc);
return

Regards

 
« Last Edit: March 20, 2017, 04:02:52 pm by Wim Brul »

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #31 on: March 20, 2017, 05:12:05 pm »
You are a phenomenon !!!!,
Anyway I comment:
The first time I ran it on the screen gave me this error
*RxUsbBulkRead(),RC=0x8050
The second time I run it but send to file, and give me error:
**RxUsbBulkRead(),RC=0x280

After this I unplug and plug the usb and give me this error:
*RxUsbBulkRead(),RC=0x0
 Data: AC
But only run well if I send to file, similar a urwin.cmd >mifile.txt

Now is nice.
Saludos
« Last Edit: March 20, 2017, 05:24:21 pm by roberto »

Wim Brul

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 28
  • Posts: 130
    • View Profile
    • Wim's home page
Re: Can I use a usb port as a com-port?
« Reply #32 on: March 20, 2017, 06:53:28 pm »
Hi Roberto,

Quote
The first time I ran it on the screen gave me this error
*RxUsbBulkRead(),RC=0x8050
The second time I run it but send to file, and give me error:
**RxUsbBulkRead(),RC=0x280

The RC=0x8050 means ERROR_HALTED_BABBLE. The device unexpectedly transmitted data to the host.
The RC=0x280 as you already know means timeout. The device did not transmit data to the host.

Quote
After this I unplug and plug the usb and give me this error:
*RxUsbBulkRead(),RC=0x0
 Data: AC
But only run well if I send to file, similar a urwin.cmd >mifile.txt

There is obviously some timing issue. You might try and test with sending only 1 data byte with RxUsbBulkWrite.

Quote
Now is nice.

Yes. Nice. We are getting there. Tomorrow I will put in some sleep instructions and see where that gets us.

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #33 on: March 21, 2017, 09:19:38 am »
There is obviously some timing issue. You might try and test with sending only 1 data byte with RxUsbBulkWrite.
I could not see any improvement by modifying this value.
But if I improve disconnecting the power to the plate, restoring the laptop, and connecting the usb after restoration worked well. I even added it's rest of code and moved the relays.
It may be that the power supply is not stabilized, and this circuit requires more precision in the voltage.
I have another problem with this laptop, and I have to wait for 16 minutes to 20 minutes, to restart it. If I do not do this, the OS / 2 turns off the laptop. This happens to me with any of the OS / 2 partitions, but not if I boot w10.
The only doubt I have is the numbering of relays. And the possible combination of starting two or more relays at the same time.

Wim Brul

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 28
  • Posts: 130
    • View Profile
    • Wim's home page
Re: Can I use a usb port as a com-port?
« Reply #34 on: March 21, 2017, 12:30:21 pm »
Hallo Roberto,

There is obviously some timing issue. You might try and test with sending only 1 data byte with RxUsbBulkWrite.
I could not see any improvement by modifying this value.
But if I improve disconnecting the power to the plate, restoring the laptop, and connecting the usb after restoration worked well. I even added it's rest of code and moved the relays.
It may be that the power supply is not stabilized, and this circuit requires more precision in the voltage.

I have seen reports on the internet that external power needed to be soldered to the power pin of the serial connector:

"Power the relay from the header pin instead of the power jack. There appears to be a big voltage drop on the power jack."

Quote
The only doubt I have is the numbering of relays. And the possible combination of starting two or more relays at the same time.

I prepared some example code that might help you out.

Code: [Select]
/* relay manipulation */
relays = x2c(b2x('11111111'));
say 'start with relays 1,2,3,4,5,6,7,8 off:' x2b(c2x(relays));

/* initialize relay switch masks */
r1off = x2c(b2x('00000001')); r1on = bitxor(r1off,relays);
r2off = x2c(b2x('00000010')); r2on = bitxor(r2off,relays);
r3off = x2c(b2x('00000100')); r3on = bitxor(r3off,relays);
r4off = x2c(b2x('00001000')); r4on = bitxor(r4off,relays);
r5off = x2c(b2x('00010000')); r5on = bitxor(r5off,relays);
r6off = x2c(b2x('00100000')); r6on = bitxor(r6off,relays);
r7off = x2c(b2x('01000000')); r7on = bitxor(r7off,relays);
r8off = x2c(b2x('10000000')); r8on = bitxor(r8off,relays);

/* relay switch example */
relays = bitand(relays,r1on);
relays = bitand(relays,r3on);
relays = bitand(relays,r5on);
relays = bitand(relays,r7on);
say 'now relays 1,3,5,7 on and 2,4,6,8,off:' x2b(c2x(relays));

/* relay switch example */
relays = bitor(relays,r1off);
relays = bitand(relays,r2on);
relays = bitor(relays,r3off);
relays = bitand(relays,r4on);
relays = bitor(relays,r5off);
relays = bitand(relays,r6on);
relays = bitor(relays,r7off);
relays = bitand(relays,r8on);
say 'now relays 1,3,5,7 off and 2,4,6,8,on:' x2b(c2x(relays));

/* relay switch example */
relays = bitor(relays,r8off);
relays = bitor(relays,r6off);
relays = bitor(relays,r4off);
relays = bitor(relays,r2off);
say 'stops with relays 1,2,3,4,5,6,7,8 off:' x2b(c2x(relays));

Regards

Neil Waldhauer

  • Sr. Member
  • ****
  • Thank You
  • -Given: 6
  • -Receive: 15
  • Posts: 294
    • View Profile
    • Blonde Guy
Re: Can I use a usb port as a com-port?
« Reply #35 on: March 21, 2017, 03:37:20 pm »
There is obviously some timing issue. You might try and test with sending only 1 data byte with RxUsbBulkWrite.
I could not see any improvement by modifying this value.
But if I improve disconnecting the power to the plate, restoring the laptop, and connecting the usb after restoration worked well. I even added it's rest of code and moved the relays.
It may be that the power supply is not stabilized, and this circuit requires more precision in the voltage.
I have another problem with this laptop, and I have to wait for 16 minutes to 20 minutes, to restart it. If I do not do this, the OS / 2 turns off the laptop. This happens to me with any of the OS / 2 partitions, but not if I boot w10.
The only doubt I have is the numbering of relays. And the possible combination of starting two or more relays at the same time.

Regarding the laptop powering off; it may be overheating.  If so, the latest ACPI from Arca Noae may fix it. 
Expert consulting for ArcaOS, OS/2 and eComStation
http://www.blondeguy.com

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #36 on: March 21, 2017, 09:58:08 pm »
Well, I can say, thank you.
Finally I gave a termination to your explanations, which have been very didactic for me.
I have left it so that only one relay can be pressed one by one.
For two reasons, do not overload the pc (being without power supply), and because it is more practical to verify that each relay works on OS / 2.

ivan

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 24
  • Posts: 632
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #37 on: March 21, 2017, 10:38:30 pm »
roberto,  There is a little bit of information on this site http://www.puntoflotante.net/ICSE014A-MODULE-8-RELAY-SERIAL-PORT-BOLT-18F2550.htm

The main point being the comment under Figure 2 regarding the power to the unit.

It appears that it does need an external power supply because on startup it pulls more power than a standard USB port can supply.

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #38 on: March 22, 2017, 01:58:47 pm »
It appears that it does need an external power supply because on startup it pulls more power than a standard USB port can supply.
Yes, you are right, so in the example I have only put the activation one by one to not overload the computer. Now I have to find an old power supply from a pc, to couple it. Like the ones that a lot of people use for arduinos and rasperripy. But in this case I will put my old laptop.
If you look, the relay plates of one or two relays, do not have the option of external power supply. I understand it's because they do not need it.
Saludos

Lars

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 20
  • Posts: 140
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #39 on: March 22, 2017, 03:12:08 pm »
Hallo Wim,

do you think that we will manage to fix USBCOM.SYS so that it will do what you now did with the help of USBCALLS.DLL ?
Obviously, USBCOM.SYS is the proper place to put this, in particular the vendor specific Setup. I remember that David Azariewicz added some specific code which I think he also took from file "pl2303.c" but maybe the vendor specific Setup is not working correctly yet.

Lars

Wim Brul

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 28
  • Posts: 130
    • View Profile
    • Wim's home page
Re: Can I use a usb port as a com-port?
« Reply #40 on: March 22, 2017, 06:37:47 pm »
Hallo Lars,

Hallo Wim,

do you think that we will manage to fix USBCOM.SYS so that it will do what you now did with the help of USBCALLS.DLL ?
Obviously, USBCOM.SYS is the proper place to put this, in particular the vendor specific Setup. I remember that David Azariewicz added some specific code which I think he also took from file "pl2303.c" but maybe the vendor specific Setup is not working correctly yet.

Lars

I must say that I am not convinced that your current USBCOM.SYS cannot be used to drive the relays. It is my understanding that Roberto did not use an external power supply at that time. May be we did not try hard enough with slight modifications of my original script to get it working. We jumped to using the USBCALLS - REXX/2 External Functions.

I agree that USBCOM.SYS is the proper place to support serial communications thru the various pl2303 chip versions. Browsing the internet I learned that the very same vendor specific code is used again and again when someone supports the pl2303 in his code. It was originally derived from snooping what happens under windows. The actual working is unknown. I think that the VendorGetMagic calls are redundant i.e. the information obtained is not used. May be windows used it to probe what pl2303 version thy are dealing with.

In practice it is impossible to reliably fix USBCOM.SYS without the hardware at hand. Moreover it could break existing support for the various pl2302 hardware that people are currently using.

Wim

ivan

  • Hero Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 24
  • Posts: 632
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #41 on: March 22, 2017, 06:58:52 pm »
Quote
Yes, you are right, so in the example I have only put the activation one by one to not overload the computer.

That is OK while running but on start up the boards firmware activates ALL of the relays at once.  This is where the problem lies because when doing that it tries to draw too much current from the USB port.

All you need for a power supply is one of the 5 volt 1.5 or 2 A phone or tablet chargers which is what we used with a similar board (we made a USB to concentric plug cable to do the job).

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #42 on: March 22, 2017, 08:15:53 pm »
from file "pl2303.c" but maybe the vendor specific Setup is not working correctly yet.
I read about this chip this can be the problem?:
Warning Notice:
Please be warned that counterfeit (fake) PL-2303HX (Chip Rev A) USB to Serial Controller ICs using Prolific's trademark logo, brandname, and device drivers, were being sold in the China market. Counterfeit IC products show exactly the same outside chip markings but generally are of poor quality and causes Windows driver compatibility issues (Yellow Mark Error Code 10 in Device Manager). We issue this warning to all our customers and consumers to avoid confusion and false purchase.
The web site of Prolific Tech:
http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #43 on: March 22, 2017, 08:51:03 pm »
Roberto did not use an external power supply at that time. May be we did not try hard enough with slight modifications of my original script to get it working.
I wanted to clarify, the problem of the two errors that sometimes occur in the starting of the plate.If I keep the circuit with current, I get the feeling that something is not reset, because with current if it does not start the first there is no way to start it.And since I'm a bit of a bitch, I do not want to get up and unplug it. What I do is remove the power-source, and only with the usb, it is easier to unplug and ready.I also need to prove with a source of more quality, in case it may or may not affect it.

Quote
what happens uInder windows.

I only tried it twice, the first one worked but it was bad (the reles did not act as expected, but they moved), and the second time could not find the device.

In os / 2 this is working fine, but always after receiving the AC command, which is where in the boot sometimes gives errors x280 and x80 ..
Saludos

roberto

  • Sr. Member
  • ****
  • Thank You
  • -Given: 13
  • -Receive: 6
  • Posts: 295
    • View Profile
Re: Can I use a usb port as a com-port?
« Reply #44 on: March 25, 2017, 01:21:13 pm »
the problem of the two errors that sometimes occur in the starting of the plate
In the relays.cmd file, I change this two lines and now is work 100% ok.
from this rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,1,Data,100);
to rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,1,Data,1000);
and in
from rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,NumBytes,,100);
to rc = RxUsbCtrlMessage(Handle,RequestType,Request,Value,Index,NumBytes,,1000);
The power supply has no influence at all. The important thing is to disconnect it (from the power supply, like the usb) before starting the usbrelays.cmd
Saludos