VB MSCOMM CONTROL PRINTING COMMAND
i tring to send print command through VB using mscomm control it working fine but it throw error:
'4 line clode is b开发者_开发知识库elow
MSComm1.CommPort = 1
MSComm1.Settings = "9600 ,N,8,1"
MSComm1.PortOpen = False
MSComm1.Output = "String to hardware"
Error: (8015) Could not set comm state, there may be one or more invalid communications parameters.
Nothing is working because your port is closed.
Line 3 should be as follows:
MSComm1.PortOpen = True
Setting the PortOpen
proptery to true
opens the port. Setting it to false
closes it.
The same 8015 error happened to me while trying to communicate with external hardware. I have only COM1 in the mainboard, and I had installed an EPSON TM-T88III in COM1, but was not using it.
I changed the COM port in the printer to COM4 (although it does not exist physically) and voilà: My VB6 program opened COM1 with no problems.
Bottomline: Doublecheck that no other hardware or driver has the port open, thus blocking it, even if you're not explicitly using that other hardware or driver.
Bottomline 2: Make sure that MSComm1.PortOpen = False
is changed to MSComm1.PortOpen = True
, other wise you'll NOT be able to communicate at all!
Do not set printer on port COM1. COM1 port will be occupied by Printer in COM1 port. When use Visual Basic MSCOMM component, you do not need any printer driver. If you do set Printer in COM1 port. You can use the following code. this code will not impacted by printer setting.
Visual Basic: Open "COM1" For Output AS #1
uninstall driver for com1, then restart windows, and try. it will work
精彩评论