Happy new year everyone!
(PB) FileToStringEx – FileToString – Helper functions
Intro:
Here’s a small but useful io function, The basic routine is also included for less demanding uses.
This function will read a text file into a string, the Ex (extended) functionality allows for defining size constraints to the return string and positioning of the file pointer for location/seeking purposes.
On big text files and in cases where you want to limit memory usage, this is a very useful routine. Otherwise the basic function works just fine.
The extended routine can also be used with a callback to set a progress bar, based on data size you can also calculate the remaining time, however that’s all beyond the scope of this post.
Code:
Procedure.s FileToStringEx( FileName.s, Flags.i = #PB_Default, NewLineCharacter.s = #CRLF$, LimitSize.i = #PB_Ignore, BeginPosition.i = #PB_Ignore, BufferSize.i = 4096 )
If (FileName)
Define.s ReturnString = ""
Define.i fp = ReadFile( #PB_Any, FileName )
If IsFile(fp)
If BufferSize > 0
FileBuffersSize( fp, BufferSize )
EndIf
If BeginPosition <> #PB_Ignore
FileSeek( fp, BeginPosition )
EndIf
While Not Eof(fp)
ReturnString + ReadString( fp, Flags, LimitSize ) + NewLineCharacter
If LimitSize <> #PB_Ignore
If Len(ReturnString) => LimitSize
Break
EndIf
EndIf
Wend
CloseFile(fp)
EndIf
ProcedureReturn ReturnString
EndIf
EndProcedure
Procedure.s FileToString( FileName.s, NewLineCharacter.s = #CRLF$, BufferSize = 4096 )
If (FileName)
Define.s ReturnString = ""
Define.i fp = ReadFile( #PB_Any, FileName )
If IsFile(fp)
FileBuffersSize( fp, BufferSize )
While Not Eof(fp)
ReturnString + ReadString( fp ) + NewLineCharacter
Wend
CloseFile(fp)
EndIf
ProcedureReturn ReturnString
EndIf
EndProcedure
Use example:
Define.s ResultingString = ""
ResultingString = FileToStringEx( "data.txt", #PB_Ascii, #CRLF$, 100, 0 ) ; read 100 characters from position 0, read as ascii, use CRLF, from data.txt.
Debug ResultingString
Keep in mind that with the basic routine the whole file will be read into memory, so you have to beware of this detail.
If you never expect file sizes to exceed a certain range, this won’t be an issue. Otherwise use the Ex function to prevent memory and other performance related issues.
If the file is not found the return string is empty, this is the expected behavior, no error codes are used but you can easily implement this.
Have fun!
Restoring a small capstan lathe – Part 1
Small but sturdy…
This small capstan lathe was salvaged from certain doom, a lot of old machinery ends up sold as scrap metal — If you can avoid it and salvage at least one, do it. They’re well worth it.

First stages of restoration, initial coat of primer (still wet), ways cleaned up some and spindle / bearings removed, along with turret and slide leaving just the headstock mounted to the bed.
First order of business:
Remove all non standard parts, this includes the fume hood and other sheet metal parts that were fitted at the previous factory.
Upon removal of the sheet metal parts, I noticed a small 3 jaw chuck was fitted to the spindle — Unsurprisingly it was stuck, but we had to remove it and take it apart anyway as part of the restoration, so we’ll put that aside for now.
A few missing parts reveal themselves, mainly the X positioning for the slide was missing (no rack, no pinion, no handle). The slide was missing the handle and the push mechanism, no motor, only a single cast iron pulley, no collet chuck.
The turret was stuck, no surprise there. Water did get inside at one point in time.
Refurbishing the turret
What’s worse than a machine in bad condition, rusty, dirty, beat up?, a machine that is also missing one or more vital parts of it’s internal mechanism!
I was missing the lock trigger for the turret, this was a huge setback because I have never seen the part, I couldn’t find information anywhere, everyone I asked had no clue or they’ve worked on different capstan lathes, with similar but not-quite-the-same lock mechanism, so I was out of luck!
Decided to go full-on CSI on the lathe, I noticed a horizontal shaft where the trigger may have been pivoting on, I also noticed a wear mark on a stop block underneath, this gave me the depth of the missing part … Now I was “just” missing the geometry of the part.
Started with a rectangular piece of flat stock, steel (unknown alloy from the scrap bin, but with relatively high carbon content based on how it machined) — Marked the height for the pivoting hole — using an informed guess — Center punched, spotted and drilled it, then reamed it up to size.
I dyed the blank trigger, fit it inside the shaft and attempted to run a cycle on the capstan, it gets stuck (not a surprise there) — But this is good news, now we have transferred onto the dye where it hit. After several iterations or removing the part, grinding away some material, dying, fitting it, cycling, etc. I managed to get a full cycle going, success!
The final part looks like like this:

Turret lathe trigger seen from the side
Locking mechanism
However the locks were not working properly, a closer inspection showed a missing locating pin that would’ve locked both parts together, I machined one out of SAE1010 1/4″ round stock, should be plenty good for this application.
Now the turret cycles properly, it just needs to be fine-tuned so it doesn’t over-spin, failing to lock automatically on every cycle (requiring the usual “hand nudge” on old, tired lathes that aren’t setup properly).
The lathe is functional in the turret department at last, most of the remaining work on the turret will be to clean up threads chasing them with taps and other basic tasks such as priming and painting.
Focus is now on the spindle, carriage and chuck. Toolposts will be required.
So how did it look like when I got it?
It looked like it belonged to a landfill, take a look:
To be fair the ways are in good shape, other than the peck-marks from who knows what (parts falling onto the ways or tools being thrown over the ways)
Here’s a close-up after cleaning them:
More to come…
Restoring an old power hacksaw – Part 2
Slight progress on the saw, mostly pictures today:

I couldn’t get some parts properly adjusted, turns out the threads were very, very dirty and some were partially damaged, so I decided to clean them up with an appropriate tap.

Since I didn’t want to machine all the parts, sleeve them, etc. To solve the issue with the wear I decided to add brass screws throughout the machine to reduce play. The holes could later on be covered up if need be. Here’s how I chucked them to face them as the last operation.

Brass screws were added as a temporary fix to deal with the play on the shaft. I drilled and tapped three holes on the main shaft bearing.

These are the temporary modifications on the saw, the other side of the con-rod has another brass screw. These are temporary until I have the time to sleeve all the parts.
Hey not bad for such an old machine!, but we can still improve it.
More on this next week…
Restoring an old power hacksaw – Part 1
A power hacksaw you say?
I always wanted one of these machines, this particular unit was based on a patent from circa 1890, amazingly these machines still have a spot in our hearts, and shops.
After many weeks of looking for one I managed to find a power hacksaw that was both in good shape (read: no missing parts, more on this later), it was listed for an “OK” price and it was also located somewhere near me, so I could have it delivered for a reasonable fee.
Despite what some people in general told me (“avoid this, buy an import bandsaw instead”) I went ahead and pulled the trigger on it. I’ve seen the import bandsaws and they require the same amount of work, or more and it is still a weak little thing that will fail sooner than later. Don’t get me wrong, most of them are meant for hobby use and will probably work fine for you after an adjustment or two, I just don’t like them.
And it arrived on my birthday!
This is what I got fresh out of the truck after a quick wipe-down…

Now THIS is what a 3/4″ HP single phase motor should look like, at least size wise. Unlike the import crap we see these days with extruded aluminum body and two end caps made out of recycled pea cans this thing is all cast iron and steel, except for the pulley.
A bit of history
According to the guy who sold it to me, this machine used to be “blue” — However I was able to count at least 4 different colors after sanding one part down, who knows how many people owned this thing, for how long, where it’s been… how many parts did it cut?, we’ll never know!
I do know this belonged to his dad, he was what I would call a general fabricator / welder and I know he bought it used already.
I’m thinking this might be from the 50s but could be slightly earlier, sadly it doesn’t have a hydraulic feed, just gravity.
What’s wrong with it?
All the parts were there, except for the depth stop. Oh well, that’s the least of my concerns right now given the wear on some of these parts, I’ll have to figure out a way to fix them at least temporarily…
- The upper belt does not fit properly and thus slips under load, the lower belt is brand new and fits perfectly, so that’s good.
- While the dovetails can be adjusted for wear/play, everything else can’t — The machine uses simple bearings (steel on iron, with grease ports) wear does occur and given the nature of this design, some parts end up being oval, which makes it even harder to fix without major machining.
- The motor needs new bearings, it sounds terrible but the start winding works fine and the centrifugal switch also works properly, so not all is bad.
- Conrod has play, the holes are not round anymore!
- Wiring, terrible job and no PG / Ground, what the heck. Needs an upgrade, although I’ll keep the Bakelite switch, since that is part of the automatic shut-off and also, original to the machine.
- Motor pulley is not running true at all. This was NOT the original motor. The machine most likely came with a 1HP 3 Phase motor as it was quite common back in the day.
- Color, this would not be my first choice. Plus they did a terrible job painting over the old paint and rust.
- I’m sure there’s something else terribly wrong with this machine but I haven’t found out yet.
First cut
Despite the machine sounding like an engine with a set of loose valves, broken rings and a bent con-rod I managed to get a relatively good first cut after assembling it. Clearly we’ll need a coolant system for this puppy…
Slow?
Turns out the previous owner mounted the blade the wrong way around… But this was a new blade, odd. He handed me three blades in total, one worn (trash) one fine, one coarse (installed). I can’t help but wonder if they used this machine like that all the time, or if he just wasn’t paying attention when he swapped the blade prior to the delivery.
At any rate, the machine now cuts as fast as a power hacksaw should cut, with a coarse blade. At least the vise seems well trammed, I noticed some shim stock underneath, interesting. We’ll measure how well it cuts later on.
For now I’ll focus on minimizing the play on the main parts of the machine, replacing bearings, etc.
Paint can wait!
To be continued…