I do also want to know how can I Display Text on Pole Display.
I write the code with VB.net 2008.
Sample Code that I write is :
If SerialPort1.IsOpen = False Then SerialPort1.Open()
SerialPort1.Write("\r\n" & RichTextBox1.Text & vbCr, 0, RichTextBox1.TextLength)
System.Threading.Thread.Sleep(1000)
If SerialPort1.IsOpen = True Then SerialPort1.Close()
I got no errors but can't display on Pole Display.
Please help me.
Sorry,
Forgot to Say. I do setup the Serial port Like This:
SerialPort1.BaudRate = 1200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = 1
SerialPort1.DataBits = 7
But It doesn't work. :(
sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
sp.Open();
// to clear the display
sp.Write(Convert.ToString((char)12));
// first line goes here
sp.WriteLine("Total : " + textBox1.Text + " RM" );
// 2nd line goes here
sp.WriteLine((char)13 + "Tendered:" + textBox2.Text + " RM");
sp.Close();
sp.Dispose();
sp = null;
Dim sp As SerialPort = New SerialPort("COM15", 9600, Parity.None, 8, StopBits.One)
sp.Open()
sp.Write(Convert.ToString(ChrW(12)))
sp.WriteLine("WELCOME HERE")
sp.WriteLine(ChrW(13) & "Total Amount:1200")
sp.Close()
sp.Dispose()
sp = Nothing
You need to setup the serial port - i.e. the baud rate, number of bits and number of stop bits. Read the display poles manual to get these settings.
edit
Before you write any code use a terminal program like windows hyper-terminal to confirm:
That your hardware is working.
if you are using the correct com port
if you are using the correct baud rate
If you need flow control (XON/XOF) or is it via hardware (RTS/CTS)
What commands you can send to the display- i.e. to clear the display & to move the top line
if the display pole dip switches are set-up correctly
Related
I am trying to add a feature to an existing program that would display the current CPU core temperature using the Open Hardware Monitor. I have it working properly on my personal computer where it displays the temperature on a tool strip status label and refreshes on a timer. However, when I copy everything over to a new PC and test run the program the temperatures it returns are always coming back roughly 25 degrees higher than what the Monitor shows. If anyone has any ideas as to why it would read correctly on one computer but not another I would appreciate it as I'm stumped...
Here are the Monitor Temps and what my program is displaying on my PC both matched up.
Open Hardware Monitor temperatures
Temperature displayed in program
Now these are the temperatures displayed on the new PC that would be shipped out.
New PC Open Hardware Monitor
Program temperature display on New PC
This is the code I am currently using to get the temps.
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
Dim cp As New Computer()
cp.Open()
cp.HDDEnabled = True
cp.FanControllerEnabled = True
cp.RAMEnabled = True
cp.GPUEnabled = True
cp.MainboardEnabled = True
cp.CPUEnabled = True
Dim Info As String = ""
Timer3.Interval = 5000
For i As Integer = 0 To cp.Hardware.Length - 1
Dim hw = cp.Hardware(i)
Select Case hw.HardwareType
Case HardwareType.CPU
ToolStripStatusLabel5.Text = "CPU" & vbCrLf
For j = 0 To hw.Sensors.Length - 1
Dim sensor = hw.Sensors(j)
If cp.Hardware(i).Sensors(j).SensorType = SensorType.Temperature Then
ToolStripStatusLabel5.Text = sensor.Name & " - " & sensor.Value & vbCrLf
End If
Next
End Select
Next
End Sub
I didn't see the error in the code, here is an example of using OpenHardwaremonitor and WMI to get the CPU temperature, maybe you can try it.
I have connected a weighing scale to my PC via an RS-232 to USB converter cable. My goal was to create a command button in excel 2007 that would place the weight from the scale into the selected cell. I got it to work using the following code in a userform.
Private Sub XMCommCRC1_OnComm()
Static sInput As String
Dim sTerminator As String
Dim Buffer As Variant
' Branch according to the CommEvent property
Select Case XMCommCRC1.CommEvent
Case XMCOMM_EV_RECEIVE
Buffer = XMCommCRC1.InputData ' Use Input property for MSComm
sInput = sInput & Buffer
If Worksheets("Settings").Range("Terminator") = "CR/LF" Then
sTerminator = vbCrLf
Else
sTerminator = vbCr
End If
If Right$(sInput, Len(sTerminator)) = sTerminator Then
XMCommCRC1.PortOpen = False
sInput = Left$(sInput, Len(sInput) - Len(sTerminator))
Select Case Left$(sInput, 2)
Case "ST", "S "
ActiveCell.Value = CDbl(Mid$(sInput, 7, 8))
ActiveCell.Activate
Case "US", "SD"
MsgBox "The balance is unstable."
Case "OL", "SI"
MsgBox "The balance is showing an eror value."
End Select
sInput = ""
End If
End Select
End Sub
Public Sub RequestBalanceData()
With Worksheets("Settings")
' Configure and open the COM port
If Not XMCommCRC1.PortOpen Then
XMCommCRC1.RThreshold = 1
XMCommCRC1.RTSEnable = True
XMCommCRC1.CommPort = .Range("COM_Port")
XMCommCRC1.Settings = .Range("Baud_Rate") & "," & _
.Range("Parity") & "," & _
.Range("Data_Bits") & "," & _
.Range("Stop_Bits")
XMCommCRC1.PortOpen = True
End If
' Send balance's "SI" (Send Immediate) command
' to request weighing data immediately
If .Range("Terminator") = "CR/LF" Then
XMCommCRC1.Output = "R" & vbCrLf
Else
XMCommCRC1.Output = "R" & vbCr
End If
End With
End Sub
I then created a command button with the following code.
Private Sub CommandButton1_Click()
UserForm1.RequestBalanceData
End Sub
When I click on the command button the weight is placed in the selected cell. However, this does not consistently happen. Sometimes when I click the button nothing will be placed in the cell, and I will have to click it multiple times until the weight is placed in the cell. I would like to fix this, but I'm not sure where to start. Is it a problem with the code itself, or is it more likely a problem with the converter or the scale itself?
Any help is appreciated.
Here is the scale: https://www.optimascale.com/product-page/op-915-bench-scale
Here is the converter cable: https://www.amazon.com/gp/product/B06XJZHCV8/ref=ox_sc_act_title_3?smid=A33N7O64F8FSDL&psc=1
Here is the tutorial I used for the code: http://www.msc-lims.com/lims/diybalance.html
Here is the ActiveX control from the tutorial that I used: http://www.hardandsoftware.net/xmcomm.htm
EDIT: I have done what Wedge has suggested and placed a Mgsbox sInput after my first End If. I have been getting inconsistent results. I am wondering if I need to change my scales sending format. The scale is currently set to sending format 4.
Here is the scale manual (sending formats are on page 21-23: https://docs.wixstatic.com/ugd/78eff6_e629ae5fe7004c7189060cca4bc7c3de.pdf
2ND EDIT:
I have connected my serial port to putty. My scale is in continuos sending mode. In putty the scale is consistently sending the following: ST,GS+ 0.00lb. However, when i try to enter the weight value in a cell, the message box sometimes displays that part of the data sent (ST,GS+ 0.00lb) has got cut off, or has been sent multiple times with one button press. Does anyone know how I would fix this?
3RD EDIT: It seems to me that the continuous sending mode (mode 4) my scale is set to is sending data too fast and is causing my code to mess up. I would like to try to make this work with the command request mode (mode 3), but I can't figure out how to properly parse the data string and place it into a cell. The sending format for command request mode is :
If anybody could help me figure out how to get this working I would greatly appreciate it.
I am developing a FedEx shipping application and I am trying to get the scale to read either dynamically or when the user ships. I need help trying to connect and get data from a usb scale in vb.net. I know how to do it for a serialport but i have no idea for a usb. How would i go about this?
this is my serialport code that i tried getting the port name to read the usb, but it kept saying "port name does not contain COM/com in it".
Private Sub testScale()
Dim Data As String
SerialPort1.Close()
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 9600
SerialPort1.Parity = IO.Ports.Parity.Odd
SerialPort1.DataBits = 7
SerialPort1.StopBits = IO.Ports.StopBits.Two
SerialPort1.Open()
SerialPort1.Write("W" & vbCr)
Data = SerialPort1.ReadExisting
txtOutput.Text = Data
SerialPort1.Close()
End Sub
I was able to achieve what i wanted using this site: http://www.bumderland.com/dev/USBHIDScale.html. Using the HidLibrary.dll and converting the C# code to vb.net.
How to send sms from your cellphone to any number using vb.net? I have searched over the internet including youtube but it seems that i could not find or cant figure out where to start. My CP cant event detected in the "phone and modem" in windows...
I have a perfect way to send SMS in visual basic, using AT-commands.
AT-commands:are instructed through which you can send and receive SMS messages, make calls from cell phone, and this is an example to Send a message:
Firstly:
Write this code in the top:
Imports System.IO.Ports
Imports System.IO
Secondly:
Write this code in the public class of form:
Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:
Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.
And write this code in the button click event.
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
Dim message As String
message = MsgRichTextBox.Text
SerialPort.Open()
If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port not available")
End If
I Hope My Answer Was Useful To You.
Important Note
Port value change from time to another and from computer to another.
I will show you how to know port value of your device by pictures.
1:Enter to Device Manager from Control Panel.
2:Right click on the device, and choose Properties.
3:Choose Modem tap, and look for port name, and use it in your application.
I already have the working codes using USB broadband kit to send a message in VB to mobile phone. Now I am doing the other way which is getting the messages from the Broadband SIM here's the code:
Imports System
Imports System.IO.Ports
Public Class ReadSMS
Dim SerialPort As New System.IO.Ports.SerialPort()
Private Sub ReadNow_Click(sender As Object, e As EventArgs) Handles ReadNow.Click
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = "COM4"
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.None
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.ReadTimeout = 10000
SerialPort.Open()
If SerialPort.IsOpen() Then
Try
Debug.Print("START")
Debug.Print(SerialPort.ReadExisting)
Debug.Print("END")
Catch ex As Exception
MsgBox("read " & ex.Message)
End Try
Else
MsgBox("Port not available")
End If
End Sub
End Class
The code above is not working. This line always return an empty value Debug.Print(SerialPort.ReadExisting) even if the SIM card has unread messages. Will that be okay if you will suggest me the best thing to do? Thanks Thanks!
The way you can read GSM is to initialize or send command to ask GSM to stream you some messages, the messages cannot stream by itself. I think you are missing the command to initate the stream of message.
You might wana read this http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS -- these are in C, but the principal remains the same.
Hope this help