Solved Set the properties of a COM port (1 Viewer)

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
Good morning.

Let's see if you can help me. I need to set the properties of a COM port to 9600-8-N-1.

I found this link where it talks about how to do it, but doesn't give any concrete example:


I have tried to put it in the way that you can see in the attached screenshot, but it turns red, so I don't know what I'm doing wrong. The error it gives is that the end of the instruction was expected.

Thank you so much.
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    296.1 KB · Views: 62

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
I come from that post. I asked the developer about my case, and he recommended me another simpler module. However, in this one I cannot set the parameters of the scale, and I was given the link that you see above to configure these parameters, but it gives me that error that I have indicated and I wanted someone to help me correct and/or write the code correctly .

Anyway thank you very much.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:07
Joined
Feb 28, 2001
Messages
27,194
The MODE command is a command-line function normally issued in the COMMAND window (CMD). It is definitely not a VBA function. The command would have to be issued outside of Access, OR you might be able to create a SHELL command that would have that effect. However, I believe that execution of that kind of command requires Admin privilege. Don't know much about that side of the problem from SHELL.

 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:07
Joined
Feb 28, 2001
Messages
27,194
Another thing: You copied the command from a place that was using optional syntax markers but what you put in the VBA line was the literal syntax description with those markers, not the actual syntax you would use.

The CMD-line command "MODE" is followed by a device name... Perhaps COM1: - but the [] in the command documentation represent OPTIONAL elements. So you would not have COM1[:] but would have either COM1 or COM1: - because they are saying the colon is optional. After that device name, but still in the same line, you could set the other parameters if you needed to do so.

I verified that the ordinary Windows Home version of the COMMAND window DOES recognize the MODE command, so you can try using a SHELL command version of it. You can get into COMMAND from Windows START button (lower left corner) >> Windows System >> Command Prompt at which point you will enter a new window with the CMD> command-line prompt. You can then type HELP MODE to see what options are available to you from your own machine. Just remember, they use syntax markers [] to show what is optional. Here is how you read the syntax.

 

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
You mean I have to put that

Shell("Mode com1: baud=<96> parity=<n> data=<8> stop=<1>", 0)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:07
Joined
Feb 28, 2001
Messages
27,194
You don't need the <> around the parameters. The <> syntax simply means you have to put something there. I.e. for example you can't put

Code:
MODE COM1: BAUD= PARITY=

.... with nothing after the <>; the <> means if you have BAUD = then some value HAS to be to the right of the = sign.
 

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
Ok, and all of this on a shell function, like I put above, doesn't it?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:07
Joined
Feb 28, 2001
Messages
27,194
Should be a single SHELL command because it is a MODE command that allows multiple options on a single command line. So unless there is some sequence you haven't discussed, it SHOULD be enough for a single SHELL command. NOTE that if it requires admin privilege, I don't know how to arrange for that to occur from Access. (Never had to do it.)
 

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
I can't probe it now because my laptop doesn't have COM ports. I have to do it tomorrow when I go to the shop.
 

zelarra821

Registered User.
Local time
Today, 11:07
Joined
Jan 14, 2019
Messages
813
The solution:

Dim PID As Variant

PID = Shell("cmd /k ""Mode COM1: BAUD=96 PARITY=n DATA=8 STOP=1""", vbNormalFocus)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:07
Joined
Feb 28, 2001
Messages
27,194
Great work in trying it. Looks like a reasonable command-line to me. If it works for you, then good luck on the next phase of what you are doing.
 

Users who are viewing this thread

Top Bottom