Sei sulla pagina 1di 3

20/12/2014

HowtoreadserialportdatainExcel2007

HowtoreadserialportdatainExcel2007
AnexamplehowtoplacetheStrokeReaderserialportActiveXonExcel2007spreadsheetandreaddatafromRS232
port,USBbarcodescannerorRS485equippedweightingmachine.

Settingupthedevelopertab
1.RunMicrosoftExcel2007usingStartbutton>AllProgramsmenu.

StrokeReaderActiveX

AboutStrokeSeader
Developerzone
Download/Buy
Propertiesandmethods
Programmingexamples
Excel2007
Access2010
VB.NET(new)
JavaScript

2. First, we need to set up the Excel's Ribbon to show the Developertab. Click on the OfficeButton and then on
ExcelOptions.

JavaScript+Binarydata
NonActiveX

SerialportprogrammingwithWinAPI

3. In the Popular group, check the Show Developer tab box and then press OK at the bottom of Excel Options
dialog.

HowtoinserttheserialportActiveXusingDevelopertab
1.OntheDevelopertab,clickontheInsertControlsbuttonandthenchooseMoreControls.

2.FromthecomponentlistintheMoreControlsdialog,chooseStrokeReader.

3.RightclickontheserialportobjecticonandthenchoosePropertiesfromthecontextmenu.

https://strokescribe.com/en/readserialportexcel2007.html

1/3

20/12/2014

HowtoreadserialportdatainExcel2007

4.InthePropertiesbox,set:
PortThedesiredserialportnumber(seePortsAvailablepropertyforthelistofserialportsavailableonyour
PC).
BaudRateThedatatransferspeed.9600isthemostpopularsettingfordataexchangewithbarcode
scanners.
DataModeWeareplanningtoreadonlyASCIIbasedbarcodes,sosetthispropertytoTEXTandallincoming
datawillberepresentedasusualVBtextstrings.
DataBitsThenumberofdatabits(5,6,7or8)ineachtransferredbyte.Setthevalueto8.
PARITYThedatavalidationschemeusedbytheserialport.NOPARITYisthemostcommonsetting.
STOPBITSThenumberofstopbitssent(orexpectedtobereceived)aftereachbyte.Setthisvalueto1.
ConnectedSetthistoTruetoconnecttotheserialport.Readthepropertyvaluetoseetheconnectionstatus.
TheActiveXwillautomaticallyreconnecttoUSBadapterwhenitreattachedtoPC.
NOTE: These are the most common values used to set up the data transfer with the most of barcode scanners.
Pleasealwaysconsulttoyourscannerprogrammer'smanual,ifunsure.

HowtoreceivethedatawithVBAprogram
1.DoubleclickontheserialportActiveXicon.PastethefollowingcodeintoVisualBasiceditorwindow.
DimbufAsString'Bufferforincomingserialdata
Dimcell_idxAsInteger'Therownumbercelltostoreareceivedbarcode
PrivateSubStrokeReader1_CommEvent(ByValEvtAsStrokeReaderLib.Event,_
ByValdataAsVariant)
SelectCaseEvt'CanbeEVT_DISCONNECTorEVT_DATAorEVT_SERIALEVENT

CaseEVT_DISCONNECT'ifUSBserialportadapterisjustdisconnectedfromthePC
MsgBox"Serialportconverterdisconnected"
CaseEVT_CONNECT
MsgBox"Connected"'ifRS232orRS485portadapterisjustconnectedtoUSBbus

CaseEVT_DATA'Incomingserialdata

https://strokescribe.com/en/readserialportexcel2007.html

2/3

20/12/2014

HowtoreadserialportdatainExcel2007

buf=buf+data'Incomingserialdataaccumulatedinbuf

Do
LF=InStr(buf,Chr(10))'MostofscannerssendASCII<LF>aftereachbarcode

IfLF=0ThenExitDo'WaitingforASCII<LF>tobereceived

s=Left(buf,LF1)'Copythedatabefore<LF>codeasthebarcodetext
s=Replace(s,Chr(13),"")'Somescannerscouldsend<CR><LF>.Remove<CR>ifpresent

buf=Right(buf,Len(buf)LF)'Cuttheparseddatafromthebuffer
'Thisisusefuliftheexternalhardwaresendsmultiplebarcodesinatime.

cell_idx=cell_idx+1'incrementtherownumberofcellwherethebarcodewillbestored
Cells(cell_idx,1)=s
Loop

EndSelect
EndSub

2.GobacktotheExcelwindowandexittheDesignmodebyclickingonDesignmodebutton:

3.ScansomebarcodesandseehowtheywillplacedintoExcelcells:

BARCODEGENERATION

TECHNOLOGIES

SERIALPORTPROGRAMMING

QRCode

VB6

Serialport/Excel

NEWSANDUPDATES

EAN13

VB.NET

Serialport/VB.NET

StrokeScribeversionhistory

DataMatrix

ASP.NET

SerialportAPIinVB6

StrokeReaderversionhistory

Code128

Excel

GS1128

Access

RSS

SITEPOLICIES
Privacypolicy
Refunds

(c)20082014strokescribe.com

https://strokescribe.com/en/readserialportexcel2007.html

3/3

Potrebbero piacerti anche