[VBSMacro] Write on CAN-BUS, data from Excel, max period ?

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
esab_el
Posts: 6
Joined: Mon 6. Jan 2020, 17:11

[VBSMacro] Write on CAN-BUS, data from Excel, max period ?

Post by esab_el » Mon 18. Jan 2021, 08:47

Hi everybody,

I would like to know, if there are a tips to write on a CAN-BUS with defined period (ojective : 1ms) using Excel sheet and a VBS Macro ?

I used the following script :

Code: Select all

'------------------------------------------------------------------------------
Sub SendMsg_NB_time()
          Dim ExcelApp, ExcelWorkbook, ExcelSheet

          Set ExcelApp = CreateObject("Excel.Application")  ' Start Excel
          ExcelApp.Visible = false ' Make Excel visible, not really required
          Set ExcelWorkbook = ExcelApp.Workbooks.Open("D:\OneDrive - SymbioFCell\Documents\SEMMOD_SW_PLATEFORM\semmod_b2_platform_dev\semmod_b2_platform\Tools\semmod_b2_platform-release_1.0\List_CAN2.xlsx")   ' Adjust path!
          Set ExcelSheet = ExcelWorkbook.Worksheets(1) ' go to Sheet 1

          ' Read all rows in the sheet
          Dim Row, Msg, n, NB_SEND, m
          NB_SEND = 100 ' Envoie de 100 x la trame
          Set Msg = Connections.Transmitmessages.Add
          row = 2 ' Messages begin on row 2
          For m = 0 To NB_SEND
					While ExcelSheet.Cells(Row, 1) <> Empty
								'Set Msg = new Connections.Transmitmessages.Add
								Msg.ID = CInt("&H" & ExcelSheet.Cells(Row, 1))
								Msg.DLC = CInt(ExcelSheet.Cells(Row, 2))
								'Msg.MsgType = 2 'pcanMsgTypeExtended 
								For n = 0 To Msg.DLC-1
										Msg.Data(n) = CInt("&H" & ExcelSheet.Cells(Row, 7+n))
								Next
								Set Msg.Connection = Connections(1)
								Msg.Write 0
								Msg.IsPaused = False
								row =row+1
								'Wait 5
					wend
			Row = 2
          Next
			'Wait 5
          ExcelApp.Quit
End Sub
Without using Delay, the period between each message is about 10-15ms.
How can I send each line on my Excel sheet every 1ms or 2ms? Is it possible to be closed to real-time machine?
Is it possible? Should I save the data on the Excel sheet to an array for faster computation?


Thank You, Emilien

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1189
Joined: Fri 10. Sep 2010, 19:34

Re: [VBSMacro] Write on CAN-BUS, data from Excel, max period ?

Post by U.Wilhelm » Mon 18. Jan 2021, 11:17

This will not be possible in Excel. You maybe can reach this time frame (1ms) in a C/C++ Application when using Multi Media Timer or seperate sending threads, but not in a scripting language in an office Application...
And - keep in mind - you use Windows ! this is no RT System.

(Topic moved to PCAN-Basic because not relevant to PCAN-Explorer 6)
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

esab_el
Posts: 6
Joined: Mon 6. Jan 2020, 17:11

Re: [VBSMacro] Write on CAN-BUS, data from Excel, max period ?

Post by esab_el » Mon 25. Jan 2021, 08:44

Hi !

Thank you for answer.

I will give up the idea about sending frame every 1ms, too big developement.

Thank you, Em.

Post Reply