tickets Discussion
MCP3008
tickets
(Discussion)
Forum for tickets comments
Last updated: 2020-08-28
SPI-Temperature SVN repository
SPI-Temperature
code
(SVN Repository)
Last updated: 2019-08-20
MCP3008 SVN repository
MCP3008
code
(SVN Repository)
Last updated: 2018-07-16
mcp3008: ./trunk/mcp3008/Libraries/SPI_MCP3008.library.xml
Bash
bash
(Bash)
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://www.plcopen.org/xml/tc6_0200">
<fileHeader companyName="" productName="CODESYS" productVersion="CODESYS V3.5 SP11" creationDateTime="2018-07-16T12:59:41.4730461" />
<contentHeader name="Linux SPI MCP3008" version="1.0.0.0" modificationDateTime="2018-07-16T12:51:11.5392363" organization="Open Source" author="3S - Smart Software Solutions GmbH">
<Comment>Library containing device support of MCP3008. The original author was 3S. Now it is maintained as open source on CODESYS Forge.</Comment>
<coordinateInfo>
<fbd>
<scaling x="1" y="1" />
</fbd>
<ld>
<scaling x="1" y="1" />
</ld>
<sfc>
<scaling x="1" y="1" />
</sfc>
</coordinateInfo>
<addData>
<data name="http://www.3s-software.com/plcopenxml/projectinformation" handleUnknown="implementation">
<ProjectInformation>
<property name="Author" type="string">3S - Smart Software Solutions GmbH</property>
<property name="Company" type="string">Open Source</property>
<property name="DefaultNamespace" type="string">MCP3008</property>
<property name="Description" type="string">Library containing device support of MCP3008. The original author was 3S. Now it is maintained as open source on CODESYS Forge.</property>
<property name="Placeholder" type="string">SPI MCP3008</property>
<property name="Project" type="string">SPI_MCP3008</property>
<property name="Released" type="boolean">false</property>
<property name="Title" type="string">Linux SPI MCP3008</property>
<property name="Version" type="version">1.0.0.0</property>
<property name="library-category-list" type="library-category-list">Target</property>
</ProjectInformation>
</data>
</addData>
</contentHeader>
<types>
<dataTypes />
<pous>
<pou name="IoDrvMCP3008" pouType="functionBlock">
<interface>
<localVars>
<variable name="_IIoDrv">
<type>
<derived name="ICmpIoDrv" />
</type>
</variable>
<variable name="_IIoDrvParameter">
<type>
<derived name="ICmpIoDrvParameter" />
</type>
</variable>
<variable name="_MCP3008">
<type>
<derived name="MCP3008" />
</type>
</variable>
<variable name="_dwInUse">
<type>
<DWORD />
</type>
</variable>
<variable name="_xBackGroundDiagStarted">
<type>
<BOOL />
</type>
</variable>
<variable name="_bDeactivated">
<type>
<BOOL />
</type>
</variable>
</localVars>
<localVars constant="true">
<variable name="CLASSID_CCmpIoDrvTemplate">
<type>
<DWORD />
</type>
<initialValue>
<simpleValue value="16#FF03" />
</initialValue>
<documentation>
<xhtml xmlns="http://www.w3.org/1999/xhtml"> TODO</xhtml>
</documentation>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/pouinheritance" handleUnknown="implementation">
<Inheritance>
<Extends>IoDrvBase</Extends>
<Implements>ICmpIoDrvParameter</Implements>
</Inheritance>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml" />
</ST>
</body>
<addData>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="FB_Exit">
<interface>
<returnType>
<BOOL />
</returnType>
<inputVars>
<variable name="bInCopyCode">
<type>
<BOOL />
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">FB_Exit_Count := FB_Exit_Count + 1;
FB_Exit := TRUE;</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="FB_Init">
<interface>
<returnType>
<BOOL />
</returnType>
<inputVars>
<variable name="bInitRetains">
<type>
<BOOL />
</type>
</variable>
<variable name="bInCopyCode">
<type>
<BOOL />
</type>
</variable>
</inputVars>
<localVars>
<variable name="Result">
<type>
<UDINT />
</type>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">FB_Init_Count := FB_Init_Count + 1;
m_Info.szDriverName := 'IoDrvMCP3008';
m_Info.szVendorName := 'Open Source';
m_info.szDeviceName := 'MCP3008';
m_Info.wModuleType := 8000;
_IIoDrv := THIS^;
_IIoDrvParameter := THIS^;
m_IBaseItf := THIS^;
m_hInterface := IoMgrRegisterInstance2(dwClassId:=CLASSID_CCmpIoDrvTemplate, pItf:=m_IBaseItf, pResult:=ADR(Result));
FB_Init := TRUE;</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="FB_Reinit">
<interface>
<returnType>
<BOOL />
</returnType>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">FB_Reinit_Count := FB_Reinit_Count + 1;
FB_Reinit := TRUE;</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="Initialize">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="wModuleType">
<type>
<UINT />
</type>
</variable>
<variable name="dwInstance">
<type>
<UDINT />
</type>
</variable>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">Initialize_Count := Initialize_Count + 1;
m_wModuleType := wModuleType;
m_dwInstance := dwInstance;
m_Info.wModuleType := wModuleType;
_MCP3008.Initialize(wModuleType, dwInstance, pConnector);
Initialize := CmpErrors.Errors.ERR_OK;</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="QueryInterface">
<interface>
<returnType>
<pointer>
<baseType>
<pointer>
<baseType>
<BYTE />
</baseType>
</pointer>
</baseType>
</pointer>
</returnType>
<inputVars>
<variable name="iid">
<type>
<DWORD />
</type>
<documentation>
<xhtml xmlns="http://www.w3.org/1999/xhtml"> InterfaceID </xhtml>
</documentation>
</variable>
<variable name="pResult">
<type>
<pointer>
<baseType>
<UDINT />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">QueryInterface_Count := QueryInterface_Count + 1;
IF iid = ITFID_ICmpIoDrv THEN
QueryInterface := ADR(_IIoDrv);
AddRef();
IF (pResult <> 0) THEN
pResult^ := Errors.ERR_OK;
END_IF
RETURN;
ELSIF iid = ITFID_ICmpIoDrvParameter THEN
QueryInterface := ADR(_IIoDrvParameter);
AddRef();
IF (pResult <> 0) THEN
pResult^ := Errors.ERR_OK;
END_IF
RETURN;
ELSE
QueryInterface := SUPER^.QueryInterface(iid, pResult);
END_IF
</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvGetModuleDiagnosis">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IF pConnector = 0 THEN
//we are called from the background task
_xBackGroundDiagStarted := TRUE;
END_IF
IoDrvGetModuleDiagnosis_Count := IoDrvGetModuleDiagnosis_Count + 1;
IoDrvGetModuleDiagnosis := Errors.ERR_NOTIMPLEMENTED;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvIdentify">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvIdentify_Count := IoDrvIdentify_Count + 1;
IoDrvIdentify := Errors.ERR_NOTIMPLEMENTED;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvReadInputs">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnectorMapList">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnectorMap" />
</baseType>
</pointer>
</type>
</variable>
<variable name="nCount">
<type>
<DINT />
</type>
</variable>
</inputVars>
<localVars>
<variable name="i">
<type>
<DINT />
</type>
</variable>
<variable name="j">
<type>
<DINT />
</type>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvReadInputs_Count := IoDrvReadInputs_Count + 1;
IF pConnectorMapList = 0 OR nCount = 0 THEN
IoDrvReadInputs := Errors.ERR_PARAMETER;
RETURN;
END_IF
FOR i:=0 TO nCount - 1 DO
IF (pConnectorMapList[i].dwNumOfChannels = 0) THEN
CONTINUE;
END_IF
FOR j:= 0 TO UDINT_TO_UINT(pConnectorMapList[i].dwNumOfChannels) - 1 DO
IoMgrCopyInputLE(ADR(pConnectorMapList[i].pChannelMapList[j]), pConnectorMapList[i].pChannelMapList[j].pParameter^.dwDriverSpecific);
END_FOR
END_FOR
IoDrvReadInputs := Errors.ERR_OK;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvScanModules">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
<variable name="ppConnectorList">
<type>
<pointer>
<baseType>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</baseType>
</pointer>
</type>
</variable>
<variable name="pnCount">
<type>
<pointer>
<baseType>
<DINT />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvScanModules_Count := IoDrvScanModules_Count + 1;
IoDrvScanModules := Errors.ERR_NOTIMPLEMENTED;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvStartBusCycle">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvStartBusCycle_Count := IoDrvStartBusCycle_Count + 1;
//if background diagnosis is not active call IoDrvGetModuleDiagnosis; normally it will be called by the runtime if DRVPROP_BACKGROUND_GETDIAG is set
IF NOT _xBackGroundDiagStarted THEN
IoDrvGetModuleDiagnosis(m_pConnector); //DRVPROP_BACKGROUND_GETDIAG not set or runtime version < V3.5.1.0
END_IF
//optional: call IoDrvWatchdogTrigger or set driver property DRVPROP_WATCHDOG in UpdateConfiguration
IoDrvWatchdogTrigger(pConnector);
IF NOT _bDeactivated THEN
_MCP3008.AfterReadInputs();
_MCP3008.BeforeWriteOutputs();
END_IF
IoDrvStartBusCycle := Errors.ERR_OK;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvUpdateConfiguration">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnectorList">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
<variable name="nCount">
<type>
<DINT />
</type>
</variable>
</inputVars>
<localVars>
<variable name="pParameter">
<type>
<pointer>
<baseType>
<derived name="IoConfigParameter" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pChild">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pstConnectorVendorName">
<type>
<pointer>
<baseType>
<string />
</baseType>
</pointer>
</type>
</variable>
<variable name="pstConnectorDeviceName">
<type>
<pointer>
<baseType>
<string />
</baseType>
</pointer>
</type>
</variable>
<variable name="Result">
<type>
<derived name="RTS_IEC_RESULT" />
</type>
</variable>
<variable name="i">
<type>
<INT />
</type>
</variable>
<variable name="bySetting">
<type>
<BYTE />
</type>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvUpdateConfiguration_Count := IoDrvUpdateConfiguration_Count + 1;
IoDrvUpdateConfiguration := Errors.ERR_OK;
IF (pConnectorList = 0) THEN
RETURN;
END_IF
m_pConnector := IoMgrConfigGetConnector(pConnectorList, ADR(nCount), m_wModuleType, m_dwInstance);
IF m_pConnector = 0 THEN
IoDrvUpdateConfiguration := ERRORS.ERR_PARAMETER;
RETURN;
END_IF
//check if device is enabled in the device tree
IF (m_pConnector^.dwFlags AND ConnectorFlags.CF_ENABLE) = 0 THEN
_bDeactivated := TRUE;
IoDrvUpdateConfiguration := Errors.ERR_OK;
RETURN;
END_IF
IF m_pConnector^.hIoDrv = 0 THEN
m_pConnector^.hIoDrv := m_hInterface;
m_pConnector^.pFather^.hIoDrv := m_hInterface;
{IF defined (pou:IoMgrConfigSetDiagnosis)}
IoMgrConfigSetDiagnosis(m_pConnector,
ConnectorFlags.CF_DRIVER_AVAILABLE OR
ConnectorFlags.CF_CONNECTOR_FOUND OR
ConnectorFlags.CF_CONNECTOR_CONFIGURED OR
ConnectorFlags.CF_CONNECTOR_ACTIVE);
{END_IF}
{IF defined (pou:IoMgrConfigSetDiagnosis)}
IoMgrConfigSetDiagnosis(m_pConnector^.pFather,
ConnectorFlags.CF_DRIVER_AVAILABLE OR
ConnectorFlags.CF_CONNECTOR_FOUND OR
ConnectorFlags.CF_CONNECTOR_CONFIGURED OR
ConnectorFlags.CF_CONNECTOR_ACTIVE);
{END_IF}
{IF defined (pou:IoMgrSetDriverProperties)}
IoMgrSetDriverProperties(m_hInterface, DRVPROP_CONSISTENCY OR DRVPROP_BACKGROUND_GETDIAG);
//Note: background diagnosis property flag is optional (supported with 3.5.1.0 runtime)
{END_IF}
//Setup I/O area
FOR i:=0 TO 7 DO
pParameter := IoMgrConfigGetParameter(m_pConnector, 1000 + i);
IF (pParameter <> 0) THEN
pParameter^.dwDriverSpecific := ADR(_MCP3008.auiValue[i]);
END_IF
END_FOR
END_IF</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvUpdateMapping">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pTaskMapList">
<type>
<pointer>
<baseType>
<derived name="IoConfigTaskMap" />
</baseType>
</pointer>
</type>
</variable>
<variable name="nCount">
<type>
<DINT />
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvUpdateMapping_Count := IoDrvUpdateMapping_Count + 1;
IF (pTaskMapList = 0) THEN
IoDrvUpdateMapping := Errors.ERR_PARAMETER;
RETURN;
END_IF
IoDrvUpdateMapping := Errors.ERR_OK;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvWatchdogTrigger">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvWatchdogTrigger_Count := IoDrvWatchdogTrigger_Count + 1;
IoDrvWatchdogTrigger := Errors.ERR_OK;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvWriteOutputs">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnectorMapList">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnectorMap" />
</baseType>
</pointer>
</type>
</variable>
<variable name="nCount">
<type>
<DINT />
</type>
</variable>
</inputVars>
<localVars>
<variable name="i">
<type>
<DINT />
</type>
</variable>
<variable name="j">
<type>
<DINT />
</type>
</variable>
<variable name="k">
<type>
<UINT />
</type>
</variable>
<variable name="wSize">
<type>
<WORD />
</type>
</variable>
<variable name="pbyIecAddress">
<type>
<pointer>
<baseType>
<BYTE />
</baseType>
</pointer>
</type>
</variable>
<variable name="bySrcValue">
<type>
<BYTE />
</type>
</variable>
<variable name="wSrcIndex">
<type>
<WORD />
</type>
</variable>
<variable name="bySrcMask">
<type>
<BYTE />
</type>
</variable>
<variable name="wDestIndex">
<type>
<WORD />
</type>
</variable>
<variable name="pdw">
<type>
<pointer>
<baseType>
<DWORD />
</baseType>
</pointer>
</type>
</variable>
<variable name="pw">
<type>
<pointer>
<baseType>
<WORD />
</baseType>
</pointer>
</type>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IoDrvWriteOutputs_Count := IoDrvWriteOutputs_Count + 1;
IoDrvWriteOutputs := Errors.ERR_OK;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvReadParameter">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pParameter">
<type>
<pointer>
<baseType>
<derived name="IoConfigParameter" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pData">
<type>
<pointer>
<baseType>
<BYTE />
</baseType>
</pointer>
</type>
</variable>
<variable name="dwBitSize">
<type>
<DWORD />
</type>
</variable>
<variable name="dwBitOffset">
<type>
<DWORD />
</type>
</variable>
</inputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IF pConnector = 0 OR pParameter = 0 OR pData = 0 THEN
IoDrvReadParameter := Errors.ERR_PARAMETER;
RETURN;
END_IF
// All standard parameters of our device are handled by the IO-manager!
IoDrvReadParameter := Errors.ERR_FAILED;
</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="IoDrvWriteParameter">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pParameter">
<type>
<pointer>
<baseType>
<derived name="IoConfigParameter" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pData">
<type>
<pointer>
<baseType>
<BYTE />
</baseType>
</pointer>
</type>
</variable>
<variable name="dwBitSize">
<type>
<DWORD />
</type>
</variable>
<variable name="dwBitOffset">
<type>
<DWORD />
</type>
</variable>
</inputVars>
<localVars>
<variable name="pParam">
<type>
<pointer>
<baseType>
<derived name="IoConfigParameter" />
</baseType>
</pointer>
</type>
</variable>
<variable name="pstDiagString">
<type>
<pointer>
<baseType>
<string />
</baseType>
</pointer>
</type>
</variable>
</localVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/attributes" handleUnknown="implementation">
<Attributes>
<Attribute Name="conditionalshow" Value="" />
</Attributes>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IF pConnector = 0 OR pParameter = 0 OR pData = 0 THEN
IoDrvWriteParameter := Errors.ERR_PARAMETER;
RETURN;
END_IF
IoDrvWriteParameter := Errors.ERR_FAILED;</xhtml>
</ST>
</body>
<BuildProperties>
<EnableSystemCall>true</EnableSystemCall>
</BuildProperties>
<addData />
</Method>
</data>
</addData>
</pou>
<pou name="MCP3008" pouType="functionBlock">
<interface>
<outputVars>
<variable name="auiValue">
<type>
<array>
<dimension lower="0" upper="7" />
<baseType>
<UINT />
</baseType>
</array>
</type>
</variable>
</outputVars>
<addData>
<data name="http://www.3s-software.com/plcopenxml/pouinheritance" handleUnknown="implementation">
<Inheritance>
<Extends>spi</Extends>
</Inheritance>
</data>
</addData>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">SUPER^();
CASE _iState OF
0:
IF SUPER^.init() THEN
_iState := 1;
END_IF
1:
_iState := 10;
END_CASE
</xhtml>
</ST>
</body>
<addData>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="AfterReadInputs">
<interface>
<returnType>
<INT />
</returnType>
<localVars>
<variable name="aby">
<type>
<array>
<dimension lower="0" upper="2" />
<baseType>
<BYTE />
</baseType>
</array>
</type>
</variable>
<variable name="usiChannel">
<type>
<USINT />
</type>
</variable>
<variable name="ui">
<type>
<UINT />
</type>
</variable>
</localVars>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">SUPER^.AfterReadInputs();
IF _iState = 10 THEN
FOR usiChannel := 0 TO 7 DO
aby[0] := 1;
aby[1] := 16#80 + SHL(usiChannel AND 7, 4);
aby[2] := 0;
IF NOT transfer(pabyTxBuffer:=ADR(aby) , pabyRxBuffer:=ADR(aby) , udiLen:=3 , uiDelayus:=0) THEN
_iState := 1000;
END_IF
ui := aby[2];
ui := ui + (BYTE_TO_UINT(aby[1]) AND 2#11) * 256;
auiValue[usiChannel] := ui;
END_FOR
END_IF
</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="BeforeWriteOutputs">
<interface>
<returnType>
<INT />
</returnType>
<localVars>
<variable name="i">
<type>
<USINT />
</type>
</variable>
</localVars>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">SUPER^.BeforeWriteOutputs();
</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
<data name="http://www.3s-software.com/plcopenxml/method" handleUnknown="implementation">
<Method name="Initialize">
<interface>
<returnType>
<UDINT />
</returnType>
<inputVars>
<variable name="wModuleType">
<type>
<UINT />
</type>
</variable>
<variable name="dwInstance">
<type>
<UDINT />
</type>
</variable>
<variable name="pConnector">
<type>
<pointer>
<baseType>
<derived name="IoConfigConnector" />
</baseType>
</pointer>
</type>
</variable>
</inputVars>
<localVars>
<variable name="pParam">
<type>
<pointer>
<baseType>
<derived name="IoConfigParameter" />
</baseType>
</pointer>
</type>
</variable>
<variable name="udiResult">
<type>
<UDINT />
</type>
</variable>
</localVars>
</interface>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">SUPER^.Initialize(wModuleType, dwInstance, pConnector);
</xhtml>
</ST>
</body>
<addData />
</Method>
</data>
</addData>
</pou>
</pous>
</types>
<instances>
<configurations />
</instances>
<addData>
<data name="http://www.3s-software.com/plcopenxml/libraries" handleUnknown="implementation">
<Libraries>
<Library Name="#CAA Types" Namespace="CAA" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" DefaultResolution="CAA Types Extern, * (CAA Technical Workgroup)" />
<Library Name="#Standard" Namespace="Standard" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" DefaultResolution="Standard, * (System)" />
<Library Name="#IoStandard" Namespace="IoStandard" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" DefaultResolution="IoStandard, * (System)" />
<Library Name="#IoDrvBase" Namespace="IoDrvBase" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" DefaultResolution="IoDrvBase, * (System)" />
<Library Name="IoDriver Parameter Interfaces, * (System)" Namespace="IIoDrvParameter" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" />
<Library Name="IoDriver Interfaces, * (System)" Namespace="IIoDrv" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" />
<Library Name="CmpErrors2 Interfaces, * (System)" Namespace="CmpErrors" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" />
<Library Name="#Raspberry Pi Peripherals" Namespace="RasPi" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" DefaultResolution="Raspberry Pi Peripherals, * (3S - Smart Software Solutions GmbH)" />
<Library Name="SysTypes2 Interfaces, * (System)" Namespace="SysTypes" HideWhenReferencedAsDependency="false" PublishSymbolsInContainer="false" SystemLibrary="false" LinkAllContent="false" />
<addData />
</Libraries>
</data>
</addData>
</project>
Last updated: 2018-07-16
mcp3008: ./trunk/mcp3008/license.txt
Bash
bash
(Bash)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
This project makes use of the following 3rd party nuget packages:
This list was generated with this command:
PM > Get-Package | Select-Object Id,LicenseUrl
Id LicenseUrl
-- ----------
DynamicLanguageRuntime https://github.com/IronLanguages/dlr/blob/master/LICENSE
IronPython https://github.com/IronLanguages/ironpython2/blob/master/LICENSE
Currently all used packages are using Apache 2.0 license.
Last updated: 2018-07-16
mcp3008: ./trunk/mcp3008/Libraries/SPI_MCP3008.library.md
Bash
bash
(Bash)
<?xml version="1.0" encoding="utf-8"?>---
~~~ST
FUNCTION_BLOCK IoDrvMCP3008 EXTENDS IoDrvBase
VAR
_IIoDrv: ICmpIoDrv;
_IIoDrvParameter: ICmpIoDrvParameter;
_MCP3008: MCP3008;
_dwInUse: DWORD;
_xBackGroundDiagStarted: BOOL;
_bDeactivated: BOOL;
END_VAR
VAR
CLASSID_CCmpIoDrvTemplate: DWORD;
END_VAR
~~~
~~~ST
~~~
---
~~~ST
METHOD FB_Exit: BOOL
VAR_INPUT
bInCopyCode: BOOL;
END_VAR
~~~
~~~ST
FB_Exit_Count := FB_Exit_Count + 1;
FB_Exit := TRUE;
~~~
---
~~~ST
METHOD FB_Init: BOOL
VAR_INPUT
bInitRetains: BOOL;
bInCopyCode: BOOL;
END_VAR
VAR
Result: UDINT;
END_VAR
~~~
~~~ST
FB_Init_Count := FB_Init_Count + 1;
m_Info.szDriverName := 'IoDrvMCP3008';
m_Info.szVendorName := 'Open Source';
m_info.szDeviceName := 'MCP3008';
m_Info.wModuleType := 8000;
_IIoDrv := THIS^;
_IIoDrvParameter := THIS^;
m_IBaseItf := THIS^;
m_hInterface := IoMgrRegisterInstance2(dwClassId:=CLASSID_CCmpIoDrvTemplate, pItf:=m_IBaseItf, pResult:=ADR(Result));
FB_Init := TRUE;
~~~
---
~~~ST
METHOD FB_Reinit: BOOL
~~~
~~~ST
FB_Reinit_Count := FB_Reinit_Count + 1;
FB_Reinit := TRUE;
~~~
---
~~~ST
METHOD Initialize: UDINT
VAR_INPUT
wModuleType: UINT;
dwInstance: UDINT;
pConnector: pointer;
END_VAR
~~~
~~~ST
Initialize_Count := Initialize_Count + 1;
m_wModuleType := wModuleType;
m_dwInstance := dwInstance;
m_Info.wModuleType := wModuleType;
_MCP3008.Initialize(wModuleType, dwInstance, pConnector);
Initialize := CmpErrors.Errors.ERR_OK;
~~~
---
~~~ST
METHOD QueryInterface: pointer
VAR_INPUT
iid: DWORD;
pResult: pointer;
END_VAR
~~~
~~~ST
QueryInterface_Count := QueryInterface_Count + 1;
IF iid = ITFID_ICmpIoDrv THEN
QueryInterface := ADR(_IIoDrv);
AddRef();
IF (pResult <> 0) THEN
pResult^ := Errors.ERR_OK;
END_IF
RETURN;
ELSIF iid = ITFID_ICmpIoDrvParameter THEN
QueryInterface := ADR(_IIoDrvParameter);
AddRef();
IF (pResult <> 0) THEN
pResult^ := Errors.ERR_OK;
END_IF
RETURN;
ELSE
QueryInterface := SUPER^.QueryInterface(iid, pResult);
END_IF
~~~
---
~~~ST
METHOD IoDrvGetModuleDiagnosis: UDINT
VAR_INPUT
pConnector: pointer;
END_VAR
~~~
~~~ST
IF pConnector = 0 THEN
//we are called from the background task
_xBackGroundDiagStarted := TRUE;
END_IF
IoDrvGetModuleDiagnosis_Count := IoDrvGetModuleDiagnosis_Count + 1;
IoDrvGetModuleDiagnosis := Errors.ERR_NOTIMPLEMENTED;
~~~
---
~~~ST
METHOD IoDrvIdentify: UDINT
VAR_INPUT
pConnector: pointer;
END_VAR
~~~
~~~ST
IoDrvIdentify_Count := IoDrvIdentify_Count + 1;
IoDrvIdentify := Errors.ERR_NOTIMPLEMENTED;
~~~
---
~~~ST
METHOD IoDrvReadInputs: UDINT
VAR_INPUT
pConnectorMapList: pointer;
nCount: DINT;
END_VAR
VAR
i: DINT;
j: DINT;
END_VAR
~~~
~~~ST
IoDrvReadInputs_Count := IoDrvReadInputs_Count + 1;
IF pConnectorMapList = 0 OR nCount = 0 THEN
IoDrvReadInputs := Errors.ERR_PARAMETER;
RETURN;
END_IF
FOR i:=0 TO nCount - 1 DO
IF (pConnectorMapList[i].dwNumOfChannels = 0) THEN
CONTINUE;
END_IF
FOR j:= 0 TO UDINT_TO_UINT(pConnectorMapList[i].dwNumOfChannels) - 1 DO
IoMgrCopyInputLE(ADR(pConnectorMapList[i].pChannelMapList[j]), pConnectorMapList[i].pChannelMapList[j].pParameter^.dwDriverSpecific);
END_FOR
END_FOR
IoDrvReadInputs := Errors.ERR_OK;
~~~
---
~~~ST
METHOD IoDrvScanModules: UDINT
VAR_INPUT
pConnector: pointer;
ppConnectorList: pointer;
pnCount: pointer;
END_VAR
~~~
~~~ST
IoDrvScanModules_Count := IoDrvScanModules_Count + 1;
IoDrvScanModules := Errors.ERR_NOTIMPLEMENTED;
~~~
---
~~~ST
METHOD IoDrvStartBusCycle: UDINT
VAR_INPUT
pConnector: pointer;
END_VAR
~~~
~~~ST
IoDrvStartBusCycle_Count := IoDrvStartBusCycle_Count + 1;
//if background diagnosis is not active call IoDrvGetModuleDiagnosis; normally it will be called by the runtime if DRVPROP_BACKGROUND_GETDIAG is set
IF NOT _xBackGroundDiagStarted THEN
IoDrvGetModuleDiagnosis(m_pConnector); //DRVPROP_BACKGROUND_GETDIAG not set or runtime version < V3.5.1.0
END_IF
//optional: call IoDrvWatchdogTrigger or set driver property DRVPROP_WATCHDOG in UpdateConfiguration
IoDrvWatchdogTrigger(pConnector);
IF NOT _bDeactivated THEN
_MCP3008.AfterReadInputs();
_MCP3008.BeforeWriteOutputs();
END_IF
IoDrvStartBusCycle := Errors.ERR_OK;
~~~
---
~~~ST
METHOD IoDrvUpdateConfiguration: UDINT
VAR_INPUT
pConnectorList: pointer;
nCount: DINT;
END_VAR
VAR
pParameter: pointer;
pChild: pointer;
pstConnectorVendorName: pointer;
pstConnectorDeviceName: pointer;
Result: RTS_IEC_RESULT;
i: INT;
bySetting: BYTE;
END_VAR
~~~
~~~ST
IoDrvUpdateConfiguration_Count := IoDrvUpdateConfiguration_Count + 1;
IoDrvUpdateConfiguration := Errors.ERR_OK;
IF (pConnectorList = 0) THEN
RETURN;
END_IF
m_pConnector := IoMgrConfigGetConnector(pConnectorList, ADR(nCount), m_wModuleType, m_dwInstance);
IF m_pConnector = 0 THEN
IoDrvUpdateConfiguration := ERRORS.ERR_PARAMETER;
RETURN;
END_IF
//check if device is enabled in the device tree
IF (m_pConnector^.dwFlags AND ConnectorFlags.CF_ENABLE) = 0 THEN
_bDeactivated := TRUE;
IoDrvUpdateConfiguration := Errors.ERR_OK;
RETURN;
END_IF
IF m_pConnector^.hIoDrv = 0 THEN
m_pConnector^.hIoDrv := m_hInterface;
m_pConnector^.pFather^.hIoDrv := m_hInterface;
{IF defined (pou:IoMgrConfigSetDiagnosis)}
IoMgrConfigSetDiagnosis(m_pConnector,
ConnectorFlags.CF_DRIVER_AVAILABLE OR
ConnectorFlags.CF_CONNECTOR_FOUND OR
ConnectorFlags.CF_CONNECTOR_CONFIGURED OR
ConnectorFlags.CF_CONNECTOR_ACTIVE);
{END_IF}
{IF defined (pou:IoMgrConfigSetDiagnosis)}
IoMgrConfigSetDiagnosis(m_pConnector^.pFather,
ConnectorFlags.CF_DRIVER_AVAILABLE OR
ConnectorFlags.CF_CONNECTOR_FOUND OR
ConnectorFlags.CF_CONNECTOR_CONFIGURED OR
ConnectorFlags.CF_CONNECTOR_ACTIVE);
{END_IF}
{IF defined (pou:IoMgrSetDriverProperties)}
IoMgrSetDriverProperties(m_hInterface, DRVPROP_CONSISTENCY OR DRVPROP_BACKGROUND_GETDIAG);
//Note: background diagnosis property flag is optional (supported with 3.5.1.0 runtime)
{END_IF}
//Setup I/O area
FOR i:=0 TO 7 DO
pParameter := IoMgrConfigGetParameter(m_pConnector, 1000 + i);
IF (pParameter <> 0) THEN
pParameter^.dwDriverSpecific := ADR(_MCP3008.auiValue[i]);
END_IF
END_FOR
END_IF
~~~
---
~~~ST
METHOD IoDrvUpdateMapping: UDINT
VAR_INPUT
pTaskMapList: pointer;
nCount: DINT;
END_VAR
~~~
~~~ST
IoDrvUpdateMapping_Count := IoDrvUpdateMapping_Count + 1;
IF (pTaskMapList = 0) THEN
IoDrvUpdateMapping := Errors.ERR_PARAMETER;
RETURN;
END_IF
IoDrvUpdateMapping := Errors.ERR_OK;
~~~
---
~~~ST
METHOD IoDrvWatchdogTrigger: UDINT
VAR_INPUT
pConnector: pointer;
END_VAR
~~~
~~~ST
IoDrvWatchdogTrigger_Count := IoDrvWatchdogTrigger_Count + 1;
IoDrvWatchdogTrigger := Errors.ERR_OK;
~~~
---
~~~ST
METHOD IoDrvWriteOutputs: UDINT
VAR_INPUT
pConnectorMapList: pointer;
nCount: DINT;
END_VAR
VAR
i: DINT;
j: DINT;
k: UINT;
wSize: WORD;
pbyIecAddress: pointer;
bySrcValue: BYTE;
wSrcIndex: WORD;
bySrcMask: BYTE;
wDestIndex: WORD;
pdw: pointer;
pw: pointer;
END_VAR
~~~
~~~ST
IoDrvWriteOutputs_Count := IoDrvWriteOutputs_Count + 1;
IoDrvWriteOutputs := Errors.ERR_OK;
~~~
---
~~~ST
METHOD IoDrvReadParameter: UDINT
VAR_INPUT
pConnector: pointer;
pParameter: pointer;
pData: pointer;
dwBitSize: DWORD;
dwBitOffset: DWORD;
END_VAR
~~~
~~~ST
IF pConnector = 0 OR pParameter = 0 OR pData = 0 THEN
IoDrvReadParameter := Errors.ERR_PARAMETER;
RETURN;
END_IF
// All standard parameters of our device are handled by the IO-manager!
IoDrvReadParameter := Errors.ERR_FAILED;
~~~
---
~~~ST
METHOD IoDrvWriteParameter: UDINT
VAR_INPUT
pConnector: pointer;
pParameter: pointer;
pData: pointer;
dwBitSize: DWORD;
dwBitOffset: DWORD;
END_VAR
VAR
pParam: pointer;
pstDiagString: pointer;
END_VAR
~~~
~~~ST
IF pConnector = 0 OR pParameter = 0 OR pData = 0 THEN
IoDrvWriteParameter := Errors.ERR_PARAMETER;
RETURN;
END_IF
IoDrvWriteParameter := Errors.ERR_FAILED;
~~~
---
~~~ST
FUNCTION_BLOCK MCP3008 EXTENDS spi
VAR_OUTPUT
auiValue: ARRAY [..] OF ;
END_VAR
~~~
~~~ST
SUPER^();
CASE _iState OF
0:
IF SUPER^.init() THEN
_iState := 1;
END_IF
1:
_iState := 10;
END_CASE
~~~
---
~~~ST
METHOD AfterReadInputs: INT
VAR
aby: ARRAY [..] OF ;
usiChannel: USINT;
ui: UINT;
END_VAR
~~~
~~~ST
SUPER^.AfterReadInputs();
IF _iState = 10 THEN
FOR usiChannel := 0 TO 7 DO
aby[0] := 1;
aby[1] := 16#80 + SHL(usiChannel AND 7, 4);
aby[2] := 0;
IF NOT transfer(pabyTxBuffer:=ADR(aby) , pabyRxBuffer:=ADR(aby) , udiLen:=3 , uiDelayus:=0) THEN
_iState := 1000;
END_IF
ui := aby[2];
ui := ui + (BYTE_TO_UINT(aby[1]) AND 2#11) * 256;
auiValue[usiChannel] := ui;
END_FOR
END_IF
~~~
---
~~~ST
METHOD BeforeWriteOutputs: INT
VAR
i: USINT;
END_VAR
~~~
~~~ST
SUPER^.BeforeWriteOutputs();
~~~
---
~~~ST
METHOD Initialize: UDINT
VAR_INPUT
wModuleType: UINT;
dwInstance: UDINT;
pConnector: pointer;
END_VAR
VAR
pParam: pointer;
udiResult: UDINT;
END_VAR
~~~
~~~ST
SUPER^.Initialize(wModuleType, dwInstance, pConnector);
~~~
Last updated: 2018-07-16
Home
SPI-Temperature
home
(WikiPage)
Download package codefailed Hardware Prerequisites Usage Wiring Add the device Configure the SPI port Configure the device Use the input values Hardware This driver supports most SPI thermal modules (like MAX31855). Those modules are returning the absolute, prescaled temperature. The main difference between most of them is the bitwidth, scaling and range. This driver is configurable, so that you can use most of them. Prerequisites You need to have the device description and driver library installed from the "SPI-Temperature" project. Usage This driver can be used in a similar way as most other CODESYS devices. Except, that the outputs are not mapped through the I/O mapping, but they are provided as an output of the FB from the device tree. Wiring The chip has to be connected to a free SPI port. We assume, that you connect the chip with a chip select that coresponds to your SPI port. ATM we don't support to use general GPIOs for chip selects. Also no daisy chaining is supported, as the device doesn't support that. This example shows the wiring of a MAX31855 with a Raspberry Pi Zero W, on SPI port 0 and chip select 0. This corresponds to "spidev0.0". Add the device The device is named SPI Temperature and has to be inserted below an SPI Master of your CODESYS project. Right click on SPI master Add Device Select the SPI Temperature Configure the SPI port The SPI port and chip select have to be set to the Pins, where you connected the chip. Double Click on the SPI Master Set the configuration parameters The first number specifies the SPI bus. The second number specifies the chip select. Configure the device As this driver is a very generic one, you have to add some configuration parameters from the datasheet. In fact these are only two values: Bitwidth Resolution Both can be usually found in the datasheet of the chio. A few common ones can be found here: [Configuration List] Use the input values After the configuration is done, the input of the sensor can be used directly from the output of the function block. rTemp := SPITemperature.rValue;
Last updated: 2019-10-05
Configuration List
SPI-Temperature
home
(WikiPage)
This is a list of the configuration of the most common chips. If you know a new one, feel free to edit this page. Chip Bitwith minimal resolution MAX31855 14Bit 0.25°C MAX6662 12Bit 0.0625°C MAX6675. 12Bit 0.25°C
Last updated: 2020-03-30
(no subject)
SPI-Temperature
home
(Thread)
Last updated: 2018-02-21
Configuration List (version 2) discussion
SPI-Temperature
home
(Thread)
Configuration List (version 2) discussion
Last updated: 2019-03-12
Home (version 2) discussion
SPI-Temperature
home
(Thread)
Home (version 2) discussion
Last updated: 2018-08-31
Home (version 8) discussion
SPI-Temperature
home
(Thread)
Home (version 8) discussion
Last updated: 2018-08-31
Home (version 5) discussion
SPI-Temperature
home
(Thread)
Home (version 5) discussion
Last updated: 2018-08-31
Home (version 4) discussion
SPI-Temperature
home
(Thread)
Home (version 4) discussion
Last updated: 2018-08-31
Configuration List (version 3) discussion
SPI-Temperature
home
(Thread)
Configuration List (version 3) discussion
Last updated: 2020-05-02
Home (version 6) discussion
SPI-Temperature
home
(Thread)
Home (version 6) discussion
Last updated: 2018-08-31
Home (version 12) discussion
SPI-Temperature
home
(Thread)
Home (version 12) discussion
Last updated: 2019-10-24
Home (version 3) discussion
SPI-Temperature
home
(Thread)
Home (version 3) discussion
Last updated: 2018-08-31
Home (version 10) discussion
SPI-Temperature
home
(Thread)
Home (version 10) discussion
Last updated: 2019-10-24
Home (version 13) discussion
SPI-Temperature
home
(Thread)
Home (version 13) discussion
Last updated: 2019-10-24
Configuration List (version 4) discussion
SPI-Temperature
home
(Thread)
Configuration List (version 4) discussion
Last updated: 2020-05-01
Home (version 1) discussion
SPI-Temperature
home
(Thread)
Home (version 1) discussion
Last updated: 2018-08-31
Home (version 9) discussion
SPI-Temperature
home
(Thread)
Home (version 9) discussion
Last updated: 2018-08-31
Configuration List (version 1) discussion
SPI-Temperature
home
(Thread)
Configuration List (version 1) discussion
Last updated: 2018-09-05
Home (version 11) discussion
SPI-Temperature
home
(Thread)
Home (version 11) discussion
Last updated: 2019-10-24