Results 1 to 12 of 12

Thread: Communicate to COM port (modem)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    5

    Unhappy Communicate to COM port (modem)

    Hi guys (and gals)

    I am generally not a very technical programmer so feel like I am beating my head against a wall, I hope that you can shed some light...

    My problem is that I am trying to pop open a cash drawer wich is connected to my machine via COM3 (my modem port) Now it seems quite a simple task you send a character or two to the port/drawer and it pops open.

    I am trying to do this via vb.net at the moment (but have tried hyperterminal and dos to test unsuccesfully) I think Ive got the connection to the com port as a little icon pops up in my taskbar displaying to that affect but doesnt show any bytes moving around. So I think that my problem lies in writing to the port correctly?

    here is an example of VB6 code they suggest you can use...

    Code:
    Dim IntFreeFile As Integer
    'Set IntFreeFile to the next available file number
    IntFreeFile = FreeFile
    
    'Open the parallel port with #IntFreeFile
    Open "LPT1" For Output As #IntFreeFile
    'Print to the parallel port, This is the line that fires the drawer.
    Print #IntFreeFile, Chr$(27) + "p" + "0"
    'Close the port
    Close IntFreeFile
    Here is the code that I am trying to write to the port with in .Net

    Code:
            Dim dt(255) As Byte
            Dim written As Integer
    
            Dim AE As New ASCIIEncoding
            Dim count As Integer = 0
    
    '-- Was using all these characters to test...
            For count = 0 To 255
                dt(count) = AE.GetBytes(Chr(count))(0)
            Next
    
            'Check if our comport is open
            If Opened = True Then
                WriteFile(hPort, dt, 256, written, Nothing)
    
           '-- Etc..
    Has anyone done anything similar? Any advice? even maybe how to do this via Hyperterminal or something...(im getting desperate!) :P

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Communicate to COM port (modem)

    You have something confused. You said that you have the drawer connected to the COM3 port, but the sample app shows the Parallel Port (LPT1. Their method writes directly to the parallel port.

    This should work for XP, but you also might want to try just using


    VB Code:
    1. Printer.Print Chr$(27) & "p" & "0"
    2. Printer.EndDoc

    Which will send the command to the printer. If the printer also has has a com connection, then you would have to write to a file to open the drawer.

    What kind of connection do you have? Is it a printer and cash drawer?

    Does it have a small round connector (com port) or a big rectangular (parallel port) or does it have both?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Communicate to COM port (modem)

    Quote Originally Posted by dglienna
    You have something confused. You said that you have the drawer connected to the COM3 port, but the sample app shows the Parallel Port (LPT1. Their method writes directly to the parallel port.

    This should work for XP, but you also might want to try just using


    VB Code:
    1. Printer.Print Chr$(27) & "p" & "0"
    2. Printer.EndDoc

    Which will send the command to the printer. If the printer also has has a com connection, then you would have to write to a file to open the drawer.

    What kind of connection do you have? Is it a printer and cash drawer?

    Does it have a small round connector (com port) or a big rectangular (parallel port) or does it have both?
    dglienna, your code will not work since this is .NET code and not VB6 code. There no longer is a Printer object in .NET.
    Quote Originally Posted by shenku
    Here is the code that I am trying to write to the port with in .Net
    The COM Port is a D-shaped 9 Pin connector.
    Last edited by RobDog888; Apr 19th, 2005 at 10:04 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Communicate to COM port (modem)

    Well, there were a few things wrong with this, and I showed the vb way that it might work as well, but if it didn't work in HyperTerminal either, I thought that the port being used was the issue. That would be the place to start, before porting to Net, which I leave to the Net guru's

    I have seen cash drawers with parallel and serial ports, that is my main concern

    the keyboard and mouse are serial devices. rd is right about the com connection on the pc being d-shaped.

    if you are using a USB port, there could also be issues...
    Last edited by dglienna; Apr 19th, 2005 at 11:10 PM.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Communicate to COM port (modem)

    The vb6 code example was from the manufacturer's suggestion. I think your main concern should be to solve
    the issue at hand in the language requested by the thread starter.

    Anyways...

    shenku, what are your parameter values for hPort? Edit: and writen?

    VB Code:
    1. WriteFile(hPort, dt, 256, written, Nothing)
    Last edited by RobDog888; Apr 19th, 2005 at 11:47 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Communicate to COM port (modem)

    This is how we did it, so I know a little about it:
    VB Code:
    1. Sub OpenDrawer()
    2.   On Error GoTo ErrorOpenDrawer
    3.   Open "//server/lpt" For Output As #1
    4.     Print #1, Chr$(27) & Chr$(112) & Chr$(0) & Chr$(25) & Chr$(250)
    5.   Close #1
    6.   On Error GoTo 0
    7.   Exit Sub
    8. ErrorOpenDrawer:
    9.   On Error GoTo 0
    10. End Sub

    and I know that it is VB. my point is that it also works in HyperTerminal
    Last edited by dglienna; Apr 20th, 2005 at 04:12 PM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    5

    Wink Re: Communicate to COM port (modem)

    Hi all

    Thanks for the input it is all brilliant, after chatting to the hardware technition guys, turns out that the connection that you plug the drawer into (i am told) has to be a specific type as you need to fire a 25v pulse down the cable to open the drawer.

    On the till system we are using apparently there is a specific port that will do this and usually on receipt printers there is also a specific port to do it from...

    So I am assuming this is he start of all my problems though Im still not convinved my .net code is working as I cant see any bytes moving to the com port. Will test more from the till hopefully today...

    re: the .net code I am using the hPort value is the reference to the "file" as it were

    Code:
     hPort = CreateFile(portname, GENERIC_READ + GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
    And the written value is used as a ref variable which holds the result of that function. ie. generally it comes back as 1 saying its written something (if you beleive it!!)

    Will post when I find out more. But think I will end up writing a OCX in VB6 *vomit*

  8. #8

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Communicate to COM port (modem)

    Also, I know this isn't code, but it's a pre built solution for handling COM and Serial ports. It may be worth spending some cash...personally I wouldn't

    $300 ouch!

    http://www.scientificcomponent.com/p...roller_net.htm

    Woka

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Communicate to COM port (modem)

    Thanks. I'll change it. It was an oversight.

    I was ejecting a receipt at the same time that I opened the drawer.
    Last edited by dglienna; Apr 20th, 2005 at 04:15 PM.

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Communicate to COM port (modem)

    And this...?
    Quote Originally Posted by dglienna
    VB Code:
    1. Printer.Print Chr$(27) & "p" & "0"
    2. Printer.EndDoc
    I am not quite sure what the above will do. What makes you think this will access the com port for a till???

    Woka

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Communicate to COM port (modem)

    The printer/drawer is hooked up to the parallel port, and when the printer receives that sequence, it opens the drawer. It is a receipt printer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width