billwhe.blogg.se

How to send to the serial port by using mscomm32.ocx
How to send to the serial port by using mscomm32.ocx








how to send to the serial port by using mscomm32.ocx

Use the dropdown boxes at the top of your VBA editor to select this. This piece of code must sit against the 'Worksheet' 'Selection Change' section. If Not Intersect(Target, Columns("A:A")) Is Nothing Then Private Sub Worksheet_SelectionChange(ByVal Target As Range) I only want the port to open when the user selects a cell in a particular column range, so I am using the following. The way I call the port open sub, is to have a worksheet onchange event. By setting it to '1' we are telling Excel to fire the 'OnComm' code whenever data is received from the serial port. RThreshold is what we are interested in here. PortOpen = True tells Excel to open the port with the above settings. 'Settings' are the device setting (baud rate, parity, etc) and are usually in the device documentation (you can also use the device with Hyperterminal to get these settings). 'CommPort' is the port number your device is connected to. The sub above will configure the port when you try and open it.

how to send to the serial port by using mscomm32.ocx

Worksheets("SerialPort").MSComm1.PortOpen = True Worksheets("SerialPort").MSComm1.InBufferSize = 4096 Worksheets("SerialPort").MSComm1.RThreshold = 1 Worksheets("SerialPort").MSComm1.CommPort = 1 'Open the COM Port with the relevant settings Insert the following into a new sub under the OnComm sub. This is the 'OnComm' event and tells excel what to do when data is received from the serial port. Once you have created the control, right-click and select 'View Code'. It does not matter where you place it - as when you open the workbook this will not be visible to the user. The cursor will change, allowing you to draw a box on the worksheet. Click the icon and select 'Microsoft Communication Control' from the list. Once you can see the toolbox- there should be a little toolbox icon. Make sure you can see the 'Control Toolbox (View>Toolbars>Control Toolbox). Now.you should be ready to program with MSCOMM!!! But if you have any concerns.or if you are not familiar with working within the registry.I would suggest doing some more research first! This worked for me.and as far as I know it is legal. Then you may need to update the registry with this key = "kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun"Īs far as the registry stuff goes, I am no expert. You should get a message to indicate that the control has been registered. Go to command prompt and type the following. So I thought I would share how I got it working on an excel worksheet to communicate with a serial device.įirst off, if you hav'nt already done so - you will need to obtain the MSCOMM32.OCX Active X library. I have had some major issues using MSCOMM and finding information/support on the web. Although I am no Excel or VBA expert.I have learnt one heck of a lot in recent times. This forum has been a great help to me in the last few months and I wanted to give something back.










How to send to the serial port by using mscomm32.ocx