I am trying to leverage the new ConvertFrom-String commandlet in the Windows Management Production Preview 5.
I have a $Sample of the string I am trying to parse data from and the $Template that I am using.
I am getting most of the data that I am looking for but for some reason am not getting all of it.
I have read a number of blog articles about the topic and have trouble shot the parsing with ConvertFrom-String Buddy but am not able to get it to extract all of the data I need.
Can you please give me insight into what I might be doing wrong that is causing most of the data to be captured but not all of it?
Thank you in advance for any help or insight.
PowerShell Version:
PS C:\Users\alozano\Desktop> $psversiontable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10514 6
Here is the powershell code being run:
$Sample = #"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
6,708,875 CM RESET CNTR2
ALL ITEMS PASSWORD LEVEL
"#
$TemplateThatFails = #"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM} RESET CNTR2
{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL
"#
$TemplateThatPartiallyWorks= #"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1}} ZBI VERSION
"#
Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
Write-Host "Using ConvertFrom-String with the TemplateThatPartiallyWorks"
$Sample | ConvertFrom-String -TemplateContent $TemplateThatPartiallyWorks| select -ExpandProperty ZebraConfig
I am getting the following results:
Using ConvertFrom-String with the TemplateThatFails
ConvertFrom-String : ConvertFrom-String appears to be having trouble parsing your data using the template you've provided. We'd love to take a look at what went wrong, if you'd like to share the data and template used to parse it. We've saved these files to
C:\Users\alozano\AppData\Local\Temp\usiqowuu.p2u.input.txt and C:\Users\alozano\AppData\Local\Temp\usiqowuu.p2u-0.template.txt - feel free to attach them in a mail to psdmfb#microsoft.com. We will review all submissions, although we can't guarantee a response.
At line:231 char:16
+ ... codedHTML | ConvertFrom-String -TemplateContent $TemplateThatFails | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [ConvertFrom-String], ResultNotFoundException
+ FullyQualifiedErrorId : ResultNotFound,Microsoft.PowerShell.Commands.StringManipulation.ConvertFromStringCommand
Using ConvertFrom-String with the TemplateThatPartiallyWorks
Serial : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
ZBIVersion : 2.1
These are the 7 lines that are at the end of $TemplateThatFails and that I have left out of $TemplateThatPartiallyWorks:
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM} RESET CNTR2
{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL
System Info:
Operating System: Windows 8.1 Enterprise 64-bit (6.3, Build 9600) (9600.winblue_r9.150322-1500)
Language: English (Regional Setting: English)
System Manufacturer: Dell Inc.
System Model: Latitude E7450
BIOS: BIOS Date: 12/29/14 05:36:41 Ver: A02.00
Processor: Intel(R) Core(TM) i5-5300U CPU # 2.30GHz (4 CPUs), ~2.3GHz
Memory: 8192MB RAM
Available OS Memory: 8082MB RAM
My setup is quite the same (i5/16Gb/Win8.1 64bit/PS 5.0.10514.6).
This is a bit crazy ; only the last line is a problem.
1 - If you isolate it completely and make it the only line in the template and in the sample, it works.
Code :
$Sample = #"
ALL ITEMS PASSWORD LEVEL
"#
$TemplateThatFails = #"
{Zebraconfig*:{PasswordLevel:ALL ITEMS}} PASSWORD LEVEL
"#
Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"
Output :
PasswordLevel
-------------
ALL ITEMS
0,13 seconds elapsed
2 - If you move it just above the previous one (in the sample and in the template), you don't get any error but the data is mixed up.
Code :
$Sample = #"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
ALL ITEMS PASSWORD LEVEL
6,708,875 CM RESET CNTR2
"#
$TemplateThatFails = #"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{PasswordLevel:ALL ITEMS} PASSWORD LEVEL
{ResetCNTR2cm:6,708,875 CM}} RESET CNTR2
"#
Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"
Output :
Serial : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
ZBIVersion : 2.1
NonResetCNTRin : 2,641,289 IN
ResetCNTR1in : 2,641,289 IN
ResetCNTR2in : 2,641,289 IN
NonResetCNTRcm : 6,708,875 CM
ResetCNTR1cm : 6,708,875 CM
PasswordLevel : CM RESET
ResetCNTR2cm : 6,708,875 CM
36,58 seconds elapsed
3 - If you move it above ZBI VERSION (sample + template), which is the last line in the partially working template, everything is fine.
Code :
$Sample = #"
JJK072821.12Z1220126.23630-01.S.JABI
+20.0 DARKNESS
6 IPS PRINT SPEED
+000 TEAR OFF
APPLICATOR PRINT MODE
NON-CONTINUOUS MEDIA TYPE
WEB SENSOR TYPE
DIRECT-THERMAL PRINT METHOD
812 PRINT WIDTH
1874 LABEL LENGTH
9.0IN 228MM MAXIMUM LENGTH
DISABLED SUPPLIES WARNING
MAINT. OFF EARLY WARNING
CONNECTED USB COMM.
READY EXTERNAL 5V
BIDIRECTIONAL PARALLEL COMM.
RS232 SERIAL COMM.
9600 BAUD
8 BITS DATA BITS
NONE PARITY
XON/XOFF HOST HANDSHAKE
NONE PROTOCOL
000 NETWORK ID
NORMAL MODE COMMUNICATIONS
<~> 7EH CONTROL PREFIX
<^> 5EH FORMAT PREFIX
<,> 2CH DELIMITER CHAR
ZPL II ZPL MODE
ACTIVE COMMAND OVERRIDE
NO MOTION MEDIA POWER UP
NO MOTION HEAD CLOSE
OFF BACKFEED
+080 LABEL TOP
+0000 LEFT POSITION
OFF VERIFIER PORT
MODE 1 APPLICATOR PORT
ENABLED ERROR ON PAUSE
PULSE MODE START PRINT SIG
FEED MODE RESYNCH MODE
DISABLED REPRINT MODE
048 WEB S.
079 MEDIA S.
065 RIBBON S.
100 TAKE LABEL
050 MARK S.
000 MARK MED S.
002 TRANS GAIN
040 TRANS BASE
086 TRANS BRIGHT
082 RIBBON GAIN
000 MARK GAIN
DPCSWFX. MODES ENABLED
.......M MODES DISABLED
832 8/MM FULL RESOLUTION
V53.17.21Z <- FIRMWARE
1.3 XML SCHEMA
V45 ---------- 19 HARDWARE ID
CUSTOMIZED CONFIGURATION
10840k...........R: RAM
2048k............E: ONBOARD FLASH
NONE FORMAT CONVERT
*** APPLICATOR P34 INTERFACE
TWINAX/COAX ID
FW VERSION IDLE DISPLAY
11/05/15 RTC DATE
11:22 RTC TIME
DISABLED ZBI
ALL ITEMS PASSWORD LEVEL
2.1 ZBI VERSION
2,641,289 IN NONRESET CNTR
2,641,289 IN RESET CNTR1
2,641,289 IN RESET CNTR2
6,708,875 CM NONRESET CNTR
6,708,875 CM RESET CNTR1
6,708,875 CM RESET CNTR2
"#
$TemplateThatFails = #"
{Zebraconfig*:{Serial:JJK072821.12Z1220126.23630-01.S.JABI}
{Darkness:+20.0} DARKNESS
{PrintSpeed:6 IPS} PRINT SPEED
{TearOff:+000} TEAR OFF
{Applicator:APPLICATOR} PRINT MODE
{MediaType:NON-CONTINUOUS} MEDIA TYPE
{SensorType:WEB} SENSOR TYPE
{PrintMethod:DIRECT-THERMAL} PRINT METHOD
{PrintWidth:812} PRINT WIDTH
{LabelLength:1874} LABEL LENGTH
{MaximumLength:9.0IN 228MM} MAXIMUM LENGTH
{SuppliesWarning:DISABLED} SUPPLIES WARNING
{EarlyWarning:MAINT. OFF} EARLY WARNING
{USBComm:CONNECTED} USB COMM.
{External5v:READY} EXTERNAL 5V
{ParallelComm:BIDIRECTIONAL} PARALLEL COMM.
{SerialComm:RS232} SERIAL COMM.
{Baud:9600} BAUD
{DataBits:8 BITS} DATA BITS
{Parity:NONE} PARITY
{HostHandshake:XON/XOFF} HOST HANDSHAKE
{Protocol:NONE} PROTOCOL
{NetworkID:000} NETWORK ID
{Communications:NORMAL MODE} COMMUNICATIONS
{ControlPrefix:<~> 7EH} CONTROL PREFIX
{FormatPrefix:<^> 5EH} FORMAT PREFIX
{Delimiter:<,> 2CH} DELIMITER CHAR
{ZPLMode:ZPL II} ZPL MODE
{CommandOverride:ACTIVE} COMMAND OVERRIDE
{MediaPowerUp:NO MOTION} MEDIA POWER UP
{HeadClose:NO MOTION} HEAD CLOSE
{Backfeed:OFF} BACKFEED
{LabelTop:+080} LABEL TOP
{LeftPosition:+0000} LEFT POSITION
{VerifierPort:OFF} VERIFIER PORT
{ApplicatorPort:MODE 1} APPLICATOR PORT
{ErrorOnPause:ENABLED} ERROR ON PAUSE
{StartPrintSig:PULSE MODE} START PRINT SIG
{ResynchMode:FEED MODE} RESYNCH MODE
{ReprintMode:DISABLED} REPRINT MODE
{WebSensor:048} WEB S.
{MediaSensor:079} MEDIA S.
{RibbonSensor:065} RIBBON S.
{TakeLabel:100} TAKE LABEL
{MarkSensor:050} MARK S.
{MarkMedSensor:000} MARK MED S.
{TrainsGain:002} TRANS GAIN
{TransBase:040} TRANS BASE
{TransBright:086} TRANS BRIGHT
{RibbonGain:082} RIBBON GAIN
{MarkGain:000} MARK GAIN
{ModesEnable:DPCSWFX.} MODES ENABLED
{ModesDisabled:.......M} MODES DISABLED
{Resolution:832 8/MM FULL} RESOLUTION
{Firmware:V53.17.21Z <-} FIRMWARE
{XMLSchema:1.3} XML SCHEMA
{HardwareID:V45 ---------- 19} HARDWARE ID
{Configuration:CUSTOMIZED} CONFIGURATION
{RAM:10840k...........R:} RAM
{OnboardFlash:2048k............E:} ONBOARD FLASH
{FormatConvert:NONE} FORMAT CONVERT
{P34Interface:*** APPLICATOR} P34 INTERFACE
TWINAX/COAX ID
{IdleDisplay:FW VERSION} IDLE DISPLAY
{RTCDate:11/05/15} RTC DATE
{RTCTime:11:22} RTC TIME
{ZBI:DISABLED} ZBI
{PasswordLevel:ALL ITEMS} PASSWORD LEVEL
{ZBIVersion:2.1} ZBI VERSION
{NonResetCNTRin:2,641,289 IN} NONRESET CNTR
{ResetCNTR1in:2,641,289 IN} RESET CNTR1
{ResetCNTR2in:2,641,289 IN} RESET CNTR2
{NonResetCNTRcm:6,708,875 CM} NONRESET CNTR
{ResetCNTR1cm:6,708,875 CM} RESET CNTR1
{ResetCNTR2cm:6,708,875 CM}} RESET CNTR2
"#
Write-Host "Using ConvertFrom-String with the TemplateThatFails"
$startTime = Get-Date
$Sample | ConvertFrom-String -TemplateContent $TemplateThatFails | select -ExpandProperty ZebraConfig
$endTime = Get-Date
$elapsed = "{0:N2}" -f (New-TimeSpan $startTime $endTime).TotalSeconds
"$elapsed seconds elapsed"
Output :
Serial : JJK072821.12Z1220126.23630-01.S.JABI
Darkness : +20.0
PrintSpeed : 6 IPS
TearOff : +000
Applicator : APPLICATOR
MediaType : NON-CONTINUOUS
SensorType : WEB
PrintMethod : DIRECT-THERMAL
PrintWidth : 812
LabelLength : 1874
MaximumLength : 9.0IN 228MM
SuppliesWarning : DISABLED
EarlyWarning : MAINT. OFF
USBComm : CONNECTED
External5v : READY
ParallelComm : BIDIRECTIONAL
SerialComm : RS232
Baud : 9600
DataBits : 8 BITS
Parity : NONE
HostHandshake : XON/XOFF
Protocol : NONE
NetworkID : 000
Communications : NORMAL MODE
ControlPrefix : <~> 7EH
FormatPrefix : <^> 5EH
Delimiter : <,> 2CH
ZPLMode : ZPL II
CommandOverride : ACTIVE
MediaPowerUp : NO MOTION
HeadClose : NO MOTION
Backfeed : OFF
LabelTop : +080
LeftPosition : +0000
VerifierPort : OFF
ApplicatorPort : MODE 1
ErrorOnPause : ENABLED
StartPrintSig : PULSE MODE
ResynchMode : FEED MODE
ReprintMode : DISABLED
WebSensor : 048
MediaSensor : 079
RibbonSensor : 065
TakeLabel : 100
MarkSensor : 050
MarkMedSensor : 000
TrainsGain : 002
TransBase : 040
TransBright : 086
RibbonGain : 082
MarkGain : 000
ModesEnable : DPCSWFX.
ModesDisabled : .......M
Resolution : 832 8/MM FULL
Firmware : V53.17.21Z <-
XMLSchema : 1.3
HardwareID : V45 ---------- 19
Configuration : CUSTOMIZED
RAM : 10840k...........R:
OnboardFlash : 2048k............E:
FormatConvert : NONE
P34Interface : *** APPLICATOR
IdleDisplay : FW VERSION
RTCDate : 11/05/15
RTCTime : 11:22
ZBI : DISABLED
PasswordLevel : ALL ITEMS
ZBIVersion : 2.1
NonResetCNTRin : 2,641,289 IN
ResetCNTR1in : 2,641,289 IN
ResetCNTR2in : 2,641,289 IN
NonResetCNTRcm : 6,708,875 CM
ResetCNTR1cm : 6,708,875 CM
ResetCNTR2cm : 6,708,875 CM
36,32 seconds elapsed
I really don't understand what's going on, but I have managed to suppress the error so I hope this will point you in the right direction.
PS : why is this so long to run ?!
Related
I am working with the Songhe Mega2560 + WiFi R3 Mega2560 + ESP8266 4MB Memory integrated circuit for a project involving connecting to a WiFi signal and reading the RSSI value.
Below is a basic sketch that I uploaded to the Mega2560 to communicate to the ESP8266 through Serial3 to test the firmware:
#include "WiFiEsp.h"
// Emulate Serial3 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL3
#include "SoftwareSerial.h"
SoftwareSerial Serial3(6, 7); // RX, TX
#endif
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial3.begin(115200);
// initialize ESP module
WiFi.init(&Serial3);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// Print WiFi MAC address
printMacAddress();
}
void loop() {
// do nothing
}
I flashed different versions of espressif's AT firmware but the serial monitor keeps showing this:
22:28:07.009 -> [WiFiEsp] Initializing ESP module
22:28:08.023 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:10.026 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:12.022 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:14.023 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:16.020 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:17.006 -> [WiFiEsp] Cannot initialize ESP module
22:28:23.017 -> [WiFiEsp] >>> TIMEOUT >>>
22:28:23.017 -> [WiFiEsp] No tag found
22:28:23.017 -> WiFi shield not present
I am not sure if it is a firmware issue so I have tried multiple versions of AT firmware. The baud rate I have set is 115200. I have been looking at many other sources online, but I cannot seem to initialize WiFiEsp's WiFi module and I would really appreciate some help on this matter.
I have been following these steps for flashing and testing.
Toggle DIP switches 5,6,7 to ON and all else OFF and RXD/TXD to RXD0
Connect USB cable from port COM3 (on my computer) to integrated PCB with Mega2560 + ESP8266 WiFi
Use esptool.py to flash firmware to the ESP8266
The latest, released firmware for ESP8266 is the "ESP8266-IDF-AT_V2.2.1.0.zip" downloadable at espressif.com
I download the factory_xxx.bin to address 0 since I read that it indicates all hardware configurations for the ESP module. Below is the command I ran:
esptool.py --chip auto --port COM3 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size 4MB 0x0 factory_WROOM-02.bin
Disconnect USB cable
Toggle DIP switches 1,2,3,4 to ON and all else OFF and RXD/TXD to RXD3
Connect USB cable and upload sketch with Arduino IDE and read serial monitor
This is the procedure I have been trying to debug. If anymore information is required for better help, please let me know and I will try my best to provide.
The screenshot below is the command I run which successfully flashes (I think):
C:\Users\[MY NAME]\Downloads\ESP8266_NONOS_SDK-3.0.5\ESP8266_NONOS_SDK-3.0.5\bin>esptool.py write_flash --flash_mode dout --flash_size 4MB-c1 0x0 boot_v1.7.bin 0x01000 at/1024+1024/user1.2048.new.5.bin 0x1fb000 blank.bin 0x1fc000 esp_init_data_default_v08.bin 0xfe000 blank.bin 0x1fe000 blank.bin
esptool.py v4.4
Found 1 serial ports
Serial port COM3
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: a4:e5:7c:b6:77:c0
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00000fff...
Flash will be erased from 0x00001000 to 0x00065fff...
Flash will be erased from 0x001fb000 to 0x001fbfff...
Flash will be erased from 0x001fc000 to 0x001fcfff...
Flash will be erased from 0x000fe000 to 0x000fefff...
Flash will be erased from 0x001fe000 to 0x001fefff...
Flash params set to 0x0360
Compressed 4080 bytes to 2936...
Wrote 4080 bytes (2936 compressed) at 0x00000000 in 0.4 seconds (effective 92.5 kbit/s)...
Hash of data verified.
Compressed 413556 bytes to 296987...
Wrote 413556 bytes (296987 compressed) at 0x00001000 in 26.2 seconds (effective 126.1 kbit/s)...
Hash of data verified.
Compressed 4096 bytes to 26...
Wrote 4096 bytes (26 compressed) at 0x001fb000 in 0.1 seconds (effective 373.3 kbit/s)...
Hash of data verified.
Compressed 128 bytes to 75...
Wrote 128 bytes (75 compressed) at 0x001fc000 in 0.1 seconds (effective 11.8 kbit/s)...
Hash of data verified.
Compressed 4096 bytes to 26...
Wrote 4096 bytes (26 compressed) at 0x000fe000 in 0.1 seconds (effective 365.1 kbit/s)...
Hash of data verified.
Compressed 4096 bytes to 26...
Wrote 4096 bytes (26 compressed) at 0x001fe000 in 0.1 seconds (effective 357.1 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
After this, I test it with Arduino's SerialPassThrough sketch replacing Serial1 with Serial3 and I get no response from running the command: AT.
I would appreciate any help on how to resolve this and where I could possibly be going wrong. Thanks!
I am unable to set the default value of a GPIO for the PRU. I would like to have a “pull-down” default, but when I boot the signal is “high” > 3.3v.
My system:
Linux beaglebone 4.19.94-ti-r62 #1buster SMP PREEMPT Sat Apr 24 00:27:24 UTC 2021 armv7l GNU/Linux
Beaglebone Black Rev C
Booting with the UIO pruss
In /boot/uEnv.txt - uboot_overlay_pru=AM335X-PRU-UIO-00A0.dtbo
Steps I took:
Went to https://kilobaser.com/beaglebone-black-device-tree-overlay-generator/ to get a dts
Selected P9_27, fast Slew, Output, Pulldown, Mode5: pr1_pru0_pru_r30_5
It generated:
/dts-v1/;
/plugin/;
/{
compatible = "ti,beaglebone", "ti,beaglebone-black";
part_number = "BS_PINMODE_P9_27_0x5";
exclusive-use =
"P9.27",
"pr1_pru0_pru_r30_5";
fragment#0 {
target = <&am33xx_pinmux>;
__overlay__ {
bs_pinmode_P9_27_0x5: pinmux_bs_pinmode_P9_27_0x5 {
pinctrl-single,pins = <0x1a4 0x5>;
};
};
};
fragment#1 {
target = <&ocp>;
__overlay__ {
bs_pinmode_P9_27_0x5_pinmux {
compatible = "bone-pinmux-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&bs_pinmode_P9_27_0x5>;
};
};
};
};
Compiled and applied the device tree
Reboot, on boot the o-scope on P9_27 goes high
I’ve tried on P9_25 as well, same result. (Update: I have tried ALL of the PRU gpios on P9 with the same result). I’ve configured it for Mode 7 (standard GPIO) and it works fine. Just Mode 5 does not seem to be responding as expected.
Can anyone verify my issue and offer a solution?
Additional clarification, the reason I believe I have configured P9_27 in the above example to be low on boot is this:
pinctrl-single,pins = <0x1a4 0x5>;
The 0x1a4 is the address offset for P9_27
0x5 = 0000 0101 - the top 5 bits are the mode in the table below. The 101 selects mode 5 (Bits 2-0) in table below. For a general GPIO, this functionality works perfectly, and there does not seem to be different rules for GPIOs associated with the PRUs
Bit Field Reset Description
6 conf_<module>_<pin>_slewctrl X Slew Control. Slew Rate: Fast is 0, Slow is 1
5 conf_<module>_<pin>_rxactive 1h Receiver Active. Input Enable: Receiver Disable 0, Receiver Enable 1
4 conf_<module>_<pin>_putypesel X Pad Pullup/Pulldown Type. Pulldown is 0, Pullup is 1
3 conf_<module>_<pin>_puden X Pad Pullup/Pulldown enable. Enabled is 0, Disabled is 1
2-0 conf_<module>_<pin>_mmode X Mode. Pad functional mux select. A number between 0 and 7 i.e. 000 and 111. This depends on which mode we require.
I have a SEL error, checked all system no sel error logs.
[root#terter ~]# ipmitool sel list
SEL has no entries
Fans power suplly looking normal too
`[root#terter ~]# ipmitool sensor list -v
Sensor ID : Fan 6 Presence (0x40)
Entity ID : 29.6
Sensor Type (Discrete): Fan
States Asserted : Availability State
[Device Present]
Sensor ID : Power Supply 1 (0x41)
Entity ID : 10.1
Sensor Type (Discrete): Power Supply
Sensor Reading : 40 Watts
States Asserted : Power Supply
[Presence detected]
`
The only problem that i found, sensor memory reading error:
[root#terter ~]# ipmitool sensor list -v
....
Sensor ID : Memory Status (0x4c)
Entity ID : 7.2
Sensor Type (Discrete): Memory
Sensor Reading : 0 error
States Asserted : Memory
[Presence Detected]
Should i change the ram, how can i be sure that i have no memory error.
Any tool checks memory ?
I am working with a Beaglebone Black and I would like to use the mmc2 slot.
according to AM335xx TRM, a beaglebone black should have 3 mmc available:
mmc0 (sd card);
mmc1 (2G flash),
mmc2.
I am trying to enable mmc2 by device tree (and I am quite sure to have the right pin settings) but, by doing
dmesg
I obtain:
/ocp/mmc#47810000: can't find DMA channel
omap_hsmmc mmc.11: unable to obtain RX DMA engine channel 65
By putting the oscilloscope probe on the header (e.g. the mmc2 clk signal), I do not see any transition.
I already removed R 160 to have mmc2 cmd accessible but I do not see any transition also there.
I tried both to enable it by
echo > /sys/devices/..../slots
and by
capemgr.enable_partno
with no success:
I can see it in
/sys/devices/..../slots
(with the L meaning loaded)..but no way to see any signal on the header.
I already googled it but answers are not clear at all.
Any ideas?
My
uname -a
is:
Linux beaglebone 3.8.13 #1 SMP Tue Jun 18 02:11:09 EDT 2013 armv7l GNU/Linux
Thanks for your help.
You need to configure the mmc2 DMA events to some DMA channel since these events are not direct mapped.
I was not able to do this successfully using device tree overlays. So I made a change in the
am335-x-bone-common.dtsi directly (not sure this is the best way though):
&edma {
ti,edma-xbar-event-map = <32 12>, /* gpevt2 -> 12 */
<30 20>, /* xdma_event_intr2 -> 20 */
+ <1 32>,
+ <2 33>;
};
In the example above the event 1 (SDTXEVT2) was mapped to channel 32 and event 2 (SDRXEVT2) to channel 33.
In case you want to pick another open DMA channel check tables 11-23. Direct Mapped and Table 11-24. Crossbar Mapped from the technical reference manual Rev J.
In your device tree overlay file add these channels in the mmc3 node:
dmas = <&edma 32
&edma 33>;
dma-names = "tx", "rx";
I'm trying to understand how I might parse binary per 4 bits if it is possible.
For example:
I have 2-byte codes that need to be parsed to determine which instruction to use
#{1NNN} where the first 4 bits tell where which instruction, and NNN represents a memory location (i.e. #{1033} says jump to memory address #{0033}
It seems to be easy to do this with full bytes, but not with half bytes:
parse #{1022} [#{10} {#22}]
because #{1} isn't valid binary!
So far, I've used giant switch statements with: #{1033} AND #{F000} = #{1000} in order to process these, but wondering how a more mature reboler might do this.
This is a rather big entry, but it addresses your needs and shows off PARSE a bit.
This is basically a working, albeit simple VM which uses the memory layout you describe above.
I set up a simple block of RAM which is an actual program that it executes when I use PARSE with the emulator grammar rule... basically, it increments an address and then jumps to that address, skipping over an NOP.
it then hits some illegal op and dies.
REBOL [
title: "simple VM using Parse, from scratch, using no external libraries"
author: "Maxim Olivier-Adlhoch"
date: 2013-11-15
]
;----
; builds a bitset with all low-order bits of a byte set,
; so only the high bits have any weight
;----
quaternary: func [value][
bs: make bitset!
reduce [
to-char (value * 16)
'-
to-char ((value * 16) + 15)
]
]
;------
; get the 12 least significant bits of a 16 bit value
LSB-12: func [address [string! binary!] ][
as-binary (address AND #{0FFF})
]
;------
i32-to-binary: func [
n [integer!]
/rev
][
n: load join "#{" [form to-hex to-integer n "}"]
either rev [head reverse n][n]
]
;------
; load value at given address. (doesn't clear the opcode).
LVAL: func [addr [binary!]][
to-integer copy/part at RAM ( (to-integer addr) + 1) 2
]
;------
; implement the opcodes which are executed by the CPU
JMP: func [addr][
print ["jumping to " addr]
continue: at RAM ((to-integer addr) + 1) ; 0 based address but 1 based indexing ;-)
]
INC: func [addr][
print ["increment value at address: " addr]
new-val: 1 + LVAL addr
addr: 1 + to-integer addr
bin-val: at (i32-to-binary new-val) 3
change at RAM addr bin-val
]
DEC: func [addr][
print ["decrement value at address: " addr]
]
NOP: func [addr][
print "skipping Nop opcode"
]
;------
; build the bitsets to match op codes
op1: quaternary 1
op2: quaternary 2
op3: quaternary 3
op4: quaternary 4
;------
; build up our CPU emulator grammar
emulator: [
some [
[
here:
[ op1 (op: 'JMP) | op2 (op: 'INC) | op3 (op: 'DEC) | op4 (op: 'NOP)] ; choose op code
:here
copy addr 2 skip (addr: LSB-12 addr) ; get unary op data
continue:
(do reduce [op addr])
:continue
]
| 2 skip (
print ["^/^/^/ERROR: illegal opcode AT: " to-binary here " offset[" -1 + index? here "]"] ; graceful crash!
)
]
]
;------
; generate a bit of binary RAM for our emulator/VM to run...
0 2 4 6 8 ; note ... don't need comments, Rebol just skips them.
RAM: #{2002100540FF30015FFF}
RAM-blowup: { 2 002 1 005 4 0FF 3 001 5 FFF } ; just to make it easier to trace op & data
parse/all RAM emulator
print "^/^/Yes that error is on purpose, I added the 5FFF bytes^/in the 'RAM' just to trigger it :-)^/"
print "notice that it doesn't run the NOP (at address #0006), ^/since we used the JMP opcode to jump over it.^/"
print "also notice that the first instruction is an increment ^/for the address which is jumped (which is misaligned on 'boot')^/"
ask "press enter to continue"
the output is as follows:
increment value at address: #{0002}
jumping to #{0006}
decrement value at address: #{0001}
ERROR: illegal opcode AT: #{5FFF} offset[ 8 ]
Yes that error is on purpose, I added the 5FFF bytes
in the 'RAM' just to trigger it :-)
notice that it doesn't run the NOP (at address #0006),
since we used the JMP opcode to jump over it.
also notice that the first instruction is an increment
for the address which is jumped (which is misaligned on 'boot')
press enter to continue